@jskit-ai/crud-server-generator 0.1.66 → 0.1.68
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/package.descriptor.mjs +9 -9
- package/package.json +7 -7
- package/templates/src/local-package/server/repository.js +1 -1
- package/templates/src/local-package/server/service.js +2 -3
- package/test/buildTemplateContext.test.js +3 -0
- package/test/crudServerGuards.test.js +83 -0
- package/test/crudService.test.js +38 -5
package/package.descriptor.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export default Object.freeze({
|
|
2
2
|
packageVersion: 1,
|
|
3
3
|
packageId: "@jskit-ai/crud-server-generator",
|
|
4
|
-
version: "0.1.
|
|
4
|
+
version: "0.1.68",
|
|
5
5
|
kind: "generator",
|
|
6
6
|
description: "CRUD server generator with routes, actions, and persistence scaffolding.",
|
|
7
7
|
options: {
|
|
@@ -152,14 +152,14 @@ export default Object.freeze({
|
|
|
152
152
|
mutations: {
|
|
153
153
|
dependencies: {
|
|
154
154
|
runtime: {
|
|
155
|
-
"@jskit-ai/auth-core": "0.1.
|
|
156
|
-
"@jskit-ai/crud-core": "0.1.
|
|
157
|
-
"@jskit-ai/database-runtime": "0.1.
|
|
158
|
-
"@jskit-ai/http-runtime": "0.1.
|
|
159
|
-
"@jskit-ai/json-rest-api-core": "0.1.
|
|
160
|
-
"@jskit-ai/kernel": "0.1.
|
|
161
|
-
"@jskit-ai/realtime": "0.1.
|
|
162
|
-
"@jskit-ai/resource-crud-core": "0.1.
|
|
155
|
+
"@jskit-ai/auth-core": "0.1.59",
|
|
156
|
+
"@jskit-ai/crud-core": "0.1.68",
|
|
157
|
+
"@jskit-ai/database-runtime": "0.1.60",
|
|
158
|
+
"@jskit-ai/http-runtime": "0.1.59",
|
|
159
|
+
"@jskit-ai/json-rest-api-core": "0.1.5",
|
|
160
|
+
"@jskit-ai/kernel": "0.1.60",
|
|
161
|
+
"@jskit-ai/realtime": "0.1.59",
|
|
162
|
+
"@jskit-ai/resource-crud-core": "0.1.5",
|
|
163
163
|
"@local/${option:namespace|kebab}": "file:packages/${option:namespace|kebab}"
|
|
164
164
|
},
|
|
165
165
|
dev: {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/crud-server-generator",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.68",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "node --test"
|
|
@@ -13,12 +13,12 @@
|
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@babel/parser": "^7.29.2",
|
|
16
|
-
"@jskit-ai/crud-core": "0.1.
|
|
17
|
-
"@jskit-ai/database-runtime": "0.1.
|
|
18
|
-
"@jskit-ai/http-runtime": "0.1.
|
|
19
|
-
"@jskit-ai/json-rest-api-core": "0.1.
|
|
20
|
-
"@jskit-ai/kernel": "0.1.
|
|
21
|
-
"@jskit-ai/resource-crud-core": "0.1.
|
|
16
|
+
"@jskit-ai/crud-core": "0.1.68",
|
|
17
|
+
"@jskit-ai/database-runtime": "0.1.60",
|
|
18
|
+
"@jskit-ai/http-runtime": "0.1.59",
|
|
19
|
+
"@jskit-ai/json-rest-api-core": "0.1.5",
|
|
20
|
+
"@jskit-ai/kernel": "0.1.60",
|
|
21
|
+
"@jskit-ai/resource-crud-core": "0.1.5",
|
|
22
22
|
"recast": "^0.23.11"
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -43,11 +43,10 @@ function createService({ ${option:namespace|camel}Repository } = {}) {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
async function deleteDocumentById(recordId, options = {}) {
|
|
46
|
-
|
|
46
|
+
return ${option:namespace|camel}Repository.deleteDocumentById(recordId, {
|
|
47
47
|
trx: options?.trx || null,
|
|
48
48
|
context: options?.context || null
|
|
49
|
-
})
|
|
50
|
-
return null;
|
|
49
|
+
});
|
|
51
50
|
}
|
|
52
51
|
|
|
53
52
|
return Object.freeze({
|
|
@@ -1040,6 +1040,9 @@ test("crud service template preserves JSON:API output and emits entity ids from
|
|
|
1040
1040
|
assert.match(templateSource, /returnJsonApiDocument\(await \$\{option:namespace\|camel\}Repository\.queryDocuments\(query, \{/);
|
|
1041
1041
|
assert.match(templateSource, /async function patchDocumentById\(recordId, payload = \{\}, options = \{\}\)/);
|
|
1042
1042
|
assert.match(templateSource, /returnJsonApiDocument\(return404IfNotFound\(await \$\{option:namespace\|camel\}Repository\.patchDocumentById\(recordId, payload, \{/);
|
|
1043
|
+
assert.match(templateSource, /async function deleteDocumentById\(recordId, options = \{\}\)/);
|
|
1044
|
+
assert.match(templateSource, /return \$\{option:namespace\|camel\}Repository\.deleteDocumentById\(recordId, \{/);
|
|
1045
|
+
assert.doesNotMatch(templateSource, /return404IfNotFound\(await \$\{option:namespace\|camel\}Repository\.deleteDocumentById/);
|
|
1043
1046
|
assert.match(templateSource, /return Object\.freeze\(\{/);
|
|
1044
1047
|
assert.match(templateSource, /export \{ createService \};/);
|
|
1045
1048
|
});
|
|
@@ -117,6 +117,50 @@ test("template createRepository builds mutable JSON:API input documents for writ
|
|
|
117
117
|
});
|
|
118
118
|
});
|
|
119
119
|
|
|
120
|
+
test("template createRepository returns null for successful deletes", async () => {
|
|
121
|
+
const calls = [];
|
|
122
|
+
const api = {
|
|
123
|
+
resources: {
|
|
124
|
+
customers: {
|
|
125
|
+
async delete(params, context) {
|
|
126
|
+
calls.push({ params, context });
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
const knex = {
|
|
132
|
+
async transaction(work) {
|
|
133
|
+
return work("trx");
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const repository = createRepository({ api, knex });
|
|
138
|
+
const result = await repository.deleteDocumentById("7", {
|
|
139
|
+
trx: "trx-1",
|
|
140
|
+
context: {
|
|
141
|
+
visibilityContext: {
|
|
142
|
+
visibility: "workspace",
|
|
143
|
+
scopeOwnerId: "7"
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
assert.equal(result, null);
|
|
149
|
+
assert.deepEqual(calls[0], {
|
|
150
|
+
params: {
|
|
151
|
+
id: "7",
|
|
152
|
+
transaction: "trx-1",
|
|
153
|
+
simplified: false
|
|
154
|
+
},
|
|
155
|
+
context: {
|
|
156
|
+
visibilityContext: {
|
|
157
|
+
visibility: "workspace",
|
|
158
|
+
scopeOwnerId: "7"
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
120
164
|
test("template createService turns missing resource records into 404 errors", async () => {
|
|
121
165
|
const service = createService({
|
|
122
166
|
customersRepository: {
|
|
@@ -139,6 +183,45 @@ test("template createService turns missing resource records into 404 errors", as
|
|
|
139
183
|
);
|
|
140
184
|
});
|
|
141
185
|
|
|
186
|
+
test("template createService returns delete results unchanged", async () => {
|
|
187
|
+
const service = createService({
|
|
188
|
+
customersRepository: {
|
|
189
|
+
async deleteDocumentById(recordId, options) {
|
|
190
|
+
return {
|
|
191
|
+
recordId,
|
|
192
|
+
options,
|
|
193
|
+
deleted: true
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
assert.deepEqual(
|
|
200
|
+
await service.deleteDocumentById("7", {
|
|
201
|
+
trx: "trx-1",
|
|
202
|
+
context: {
|
|
203
|
+
visibilityContext: {
|
|
204
|
+
visibility: "workspace",
|
|
205
|
+
scopeOwnerId: "7"
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}),
|
|
209
|
+
{
|
|
210
|
+
recordId: "7",
|
|
211
|
+
options: {
|
|
212
|
+
trx: "trx-1",
|
|
213
|
+
context: {
|
|
214
|
+
visibilityContext: {
|
|
215
|
+
visibility: "workspace",
|
|
216
|
+
scopeOwnerId: "7"
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
deleted: true
|
|
221
|
+
}
|
|
222
|
+
);
|
|
223
|
+
});
|
|
224
|
+
|
|
142
225
|
test("template createActions requires namespaced CRUD permissions by default", () => {
|
|
143
226
|
const actions = createActions({ surface: "admin" });
|
|
144
227
|
|
package/test/crudService.test.js
CHANGED
|
@@ -30,7 +30,7 @@ test("crudService exposes the explicit JSON:API CRUD service contract", async ()
|
|
|
30
30
|
},
|
|
31
31
|
async deleteDocumentById(recordId, options) {
|
|
32
32
|
calls.push(["deleteDocumentById", recordId, options]);
|
|
33
|
-
return
|
|
33
|
+
return null;
|
|
34
34
|
}
|
|
35
35
|
};
|
|
36
36
|
|
|
@@ -131,9 +131,42 @@ test("crudService throws 404 when a document is missing", async () => {
|
|
|
131
131
|
() => service.patchDocumentById(9, { textField: "Changed" }, {}),
|
|
132
132
|
(error) => error?.status === 404 && error?.message === "Document not found."
|
|
133
133
|
);
|
|
134
|
+
});
|
|
134
135
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
136
|
+
test("crudService returns delete results unchanged", async () => {
|
|
137
|
+
const service = createService({
|
|
138
|
+
customersRepository: {
|
|
139
|
+
async deleteDocumentById(recordId, options) {
|
|
140
|
+
return {
|
|
141
|
+
recordId,
|
|
142
|
+
options,
|
|
143
|
+
deleted: true
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
const result = await service.deleteDocumentById(9, {
|
|
150
|
+
trx: "trx-1",
|
|
151
|
+
context: {
|
|
152
|
+
visibilityContext: {
|
|
153
|
+
visibility: "workspace",
|
|
154
|
+
scopeOwnerId: "7"
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
assert.deepEqual(result, {
|
|
160
|
+
recordId: 9,
|
|
161
|
+
options: {
|
|
162
|
+
trx: "trx-1",
|
|
163
|
+
context: {
|
|
164
|
+
visibilityContext: {
|
|
165
|
+
visibility: "workspace",
|
|
166
|
+
scopeOwnerId: "7"
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
deleted: true
|
|
171
|
+
});
|
|
139
172
|
});
|