Skip to content

Commit

Permalink
Add more parameters to BaseServer
Browse files Browse the repository at this point in the history
  • Loading branch information
djhi committed Jun 3, 2024
1 parent ea1a511 commit c657193
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/BaseServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { CollectionItem, Query, QueryFunction } from './types.js';

export class BaseServer {
baseUrl: string | null = null;
identifierName = 'id';
loggingEnabled = false;
defaultQuery: QueryFunction = () => ({});
batchUrl: string | null = null;
Expand All @@ -13,17 +14,35 @@ export class BaseServer {

constructor({
baseUrl = '',
batchUrl = null,
data,
defaultQuery = () => ({}),
identifierName = 'id',
getNewId,
loggingEnabled = false,
}: {
baseUrl?: string;
batchUrl?: string | null;
data?: Record<string, CollectionItem[] | CollectionItem>;
defaultQuery?: QueryFunction;
identifierName?: string;
getNewId?: () => number | string;
loggingEnabled?: boolean;
} = {}) {
this.baseUrl = baseUrl;
this.batchUrl = batchUrl;
this.getNewId = getNewId;
this.loggingEnabled = loggingEnabled;
this.identifierName = identifierName;
this.defaultQuery = defaultQuery;

if (data) {
this.init(data);
}
}

/**
* Shortcut for adding several collections if identifierName is always 'id'
* Shortcut for adding several collections if identifierName is always the same
*/
init(data: Record<string, CollectionItem[] | CollectionItem>) {
for (const name in data) {
Expand All @@ -33,7 +52,7 @@ export class BaseServer {
name,
new Collection({
items: value,
identifierName: 'id',
identifierName: this.identifierName,
getNewId: this.getNewId,
}),
);
Expand Down

0 comments on commit c657193

Please sign in to comment.