kodzero-front-sdk-alfa 0.0.8 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/Kodzero.d.ts CHANGED
@@ -12,7 +12,7 @@ declare class Kodzero {
12
12
  api: typeof FluidFetch;
13
13
  constructor(options: Options);
14
14
  createModel: <T extends {
15
- _id?: string;
15
+ _id: string | null;
16
16
  }, M = {}>(options: Omit<ModelOptions, "host">) => {
17
17
  new (data: T): import("./model/BaseModel.js").default<T> & M;
18
18
  get(id: string): Promise<import("./model/BaseModel.js").default<T> & M>;
@@ -6,7 +6,7 @@ export interface ModelOptions {
6
6
  schema?: Record<string, any>;
7
7
  }
8
8
  declare class BaseModel<T extends {
9
- _id?: string;
9
+ _id: string | null;
10
10
  }> {
11
11
  host: string;
12
12
  collection: string;
@@ -9,7 +9,7 @@ export interface FindManyOptions {
9
9
  fields?: string[];
10
10
  }
11
11
  declare const createModel: <T extends {
12
- _id?: string;
12
+ _id: string | null;
13
13
  }, M = {}>(options: ModelOptions, apiClient: typeof FluidFetch) => {
14
14
  new (data: T): BaseModel<T> & M;
15
15
  get(id: string): Promise<BaseModel<T> & M>;
@@ -18,7 +18,10 @@ const createModel = (options, apiClient) => {
18
18
  const response = await Model.apiClient.get(getUrl);
19
19
  await Model._handleApiError(response);
20
20
  const json = await response.json();
21
- return new Model(json.result);
21
+ const model = new Model(json.result);
22
+ model.modelData._id = json.result._id;
23
+ model.id = json.result._id;
24
+ return model;
22
25
  }
23
26
  static registerMethod(name, fn) {
24
27
  Model.prototype[name] = fn;
@@ -148,8 +151,9 @@ const createModel = (options, apiClient) => {
148
151
  }
149
152
  constructor(data) {
150
153
  super(options, apiClient);
151
- this.modelData = { ...data, _id: null };
152
- this.id = null;
154
+ this.modelData = { ...data };
155
+ this.modelData._id = data._id || null;
156
+ this.id = data._id || null;
153
157
  }
154
158
  };
155
159
  return Model;
@@ -9,7 +9,7 @@ class BaseModelSchema {
9
9
  type: String
10
10
  },
11
11
  schema: {
12
- type: Schema,
12
+ type: Object,
13
13
  required: false
14
14
  }
15
15
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kodzero-front-sdk-alfa",
3
- "version": "0.0.8",
3
+ "version": "0.0.12",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "tsc": "tsc -b src/",
@@ -15,8 +15,8 @@
15
15
  "license": "ISC",
16
16
  "description": "",
17
17
  "dependencies": {
18
- "fluid-fetch": "^0.0.2",
19
- "validno": "^0.3.5"
18
+ "fluid-fetch": "^0.0.3",
19
+ "validno": "^0.4.1"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@babel/plugin-transform-modules-commonjs": "^7.27.1",
package/src/Kodzero.ts CHANGED
@@ -27,7 +27,7 @@ class Kodzero {
27
27
  })
28
28
  }
29
29
 
30
- createModel = <T extends { _id?: string }, M = {}>(options: Omit<ModelOptions, 'host'>) => {
30
+ createModel = <T extends { _id: string | null }, M = {}>(options: Omit<ModelOptions, 'host'>) => {
31
31
  return createModel<T, M>({...options, host: this.host}, this.api)
32
32
  }
33
33
  }
@@ -15,7 +15,7 @@ export interface ModelOptions {
15
15
  /**
16
16
  * Base model constructor that expose main methods to work with user-created model
17
17
  */
18
- class BaseModel<T extends { _id?: string }> {
18
+ class BaseModel<T extends { _id: string | null }> {
19
19
  host: string
20
20
  collection: string
21
21
  modelData: T = {} as T
@@ -18,7 +18,7 @@ export interface FindManyOptions {
18
18
  * Creates custom model with the specified schema, API options, etc.
19
19
  */
20
20
  const createModel = <
21
- T extends { _id?: string },
21
+ T extends { _id: string | null},
22
22
  M = {}
23
23
  >(options: ModelOptions, apiClient: typeof FluidFetch) => {
24
24
  const Model = class extends BaseModel<T> {
@@ -40,8 +40,11 @@ const createModel = <
40
40
  await Model._handleApiError(response);
41
41
 
42
42
  const json = await response.json();
43
+ const model = new Model(json.result);
44
+ model.modelData._id = json.result._id;
45
+ model.id = json.result._id;
43
46
 
44
- return new Model(json.result);
47
+ return model;
45
48
  }
46
49
 
47
50
  /**
@@ -106,7 +109,7 @@ const createModel = <
106
109
 
107
110
  static async create(data: T): Promise<T> {
108
111
  const createUrl = buildURL(Model.host, Model.collection)
109
- const {_id, ...dataWithoutId} = data as T & {_id?: string};
112
+ const {_id, ...dataWithoutId} = data as T & {_id: string | null};
110
113
 
111
114
  const response = await Model.apiClient.post(createUrl)
112
115
  .body(dataWithoutId)
@@ -230,8 +233,9 @@ const createModel = <
230
233
  constructor(data: T) {
231
234
  super(options, apiClient)
232
235
 
233
- this.modelData = {...data, _id: null}
234
- this.id = null;
236
+ this.modelData = {...data}
237
+ this.modelData._id = data._id || null;
238
+ this.id = data._id || null;
235
239
  }
236
240
  }
237
241
 
@@ -11,7 +11,7 @@ class BaseModelSchema {
11
11
  type: String
12
12
  },
13
13
  schema: {
14
- type: Schema,
14
+ type: Object,
15
15
  required: false
16
16
  }
17
17
  })