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 +1 -1
- package/dist/model/BaseModel.d.ts +1 -1
- package/dist/model/createModel.d.ts +1 -1
- package/dist/model/createModel.js +7 -3
- package/dist/schemas/baseModel.js +1 -1
- package/package.json +3 -3
- package/src/Kodzero.ts +1 -1
- package/src/model/BaseModel.ts +1 -1
- package/src/model/createModel.ts +9 -5
- package/src/schemas/baseModel.ts +1 -1
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
|
|
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>;
|
|
@@ -9,7 +9,7 @@ export interface FindManyOptions {
|
|
|
9
9
|
fields?: string[];
|
|
10
10
|
}
|
|
11
11
|
declare const createModel: <T extends {
|
|
12
|
-
_id
|
|
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
|
-
|
|
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
|
|
152
|
-
this.
|
|
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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kodzero-front-sdk-alfa",
|
|
3
|
-
"version": "0.0.
|
|
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.
|
|
19
|
-
"validno": "^0.
|
|
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
|
|
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
|
}
|
package/src/model/BaseModel.ts
CHANGED
|
@@ -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
|
|
18
|
+
class BaseModel<T extends { _id: string | null }> {
|
|
19
19
|
host: string
|
|
20
20
|
collection: string
|
|
21
21
|
modelData: T = {} as T
|
package/src/model/createModel.ts
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
234
|
-
this.
|
|
236
|
+
this.modelData = {...data}
|
|
237
|
+
this.modelData._id = data._id || null;
|
|
238
|
+
this.id = data._id || null;
|
|
235
239
|
}
|
|
236
240
|
}
|
|
237
241
|
|