@jskit-ai/crud-core 0.1.193 → 0.1.194

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.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/crud-core",
3
- "version": "0.1.193",
3
+ "version": "0.1.194",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "node --test"
@@ -23,9 +23,9 @@
23
23
  "./server/routeContracts": "./src/server/routeContracts.js"
24
24
  },
25
25
  "dependencies": {
26
- "@jskit-ai/database-runtime": "0.1.182",
27
- "@jskit-ai/json-rest-api-core": "0.1.126",
28
- "@jskit-ai/resource-crud-core": "0.1.124",
26
+ "@jskit-ai/database-runtime": "0.1.183",
27
+ "@jskit-ai/json-rest-api-core": "0.1.127",
28
+ "@jskit-ai/resource-crud-core": "0.1.125",
29
29
  "json-rest-schema": "^1.0.17"
30
30
  },
31
31
  "description": "Shared server-side CRUD service, repository, route, and query helpers.",
@@ -45,7 +45,7 @@
45
45
  }
46
46
  },
47
47
  "peerDependencies": {
48
- "@jskit-ai/http-runtime": "0.1.180",
49
- "@jskit-ai/kernel": "0.1.182"
48
+ "@jskit-ai/http-runtime": "0.1.181",
49
+ "@jskit-ai/kernel": "0.1.183"
50
50
  }
51
51
  }
@@ -8,8 +8,8 @@
8
8
  "./shared": "./src/shared/index.js"
9
9
  },
10
10
  "dependencies": {
11
- "@jskit-ai/crud-core": "0.1.193",
12
- "@jskit-ai/resource-crud-core": "0.1.124"
11
+ "@jskit-ai/crud-core": "0.1.194",
12
+ "@jskit-ai/resource-crud-core": "0.1.125"
13
13
  },
14
14
  "jskit": {
15
15
  "kind": "runtime",
@@ -0,0 +1,140 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import knexLib from "knex";
4
+ import { createServiceToolCatalog } from "@jskit-ai/assistant-core/server";
5
+ import { createActionCatalogue } from "@jskit-ai/kernel/server/actions";
6
+ import {
7
+ addResourceIfMissing,
8
+ createJsonRestApiHost,
9
+ createJsonRestResourceScopeOptions
10
+ } from "@jskit-ai/json-rest-api-core/server/jsonRestApiHost";
11
+ import { defineCrudResource } from "@jskit-ai/resource-crud-core/shared/crudResource";
12
+ import { createCrudJsonApiActions } from "../src/server/jsonApiModule/actions.js";
13
+ import { createCrudJsonApiRepository } from "../src/server/jsonApiModule/repository.js";
14
+ import { createCrudJsonApiService } from "../src/server/jsonApiModule/service.js";
15
+
16
+ test("assistant list traverses real SQL pages with sparse fields and capped limits", async (t) => {
17
+ const knex = knexLib({
18
+ client: "better-sqlite3",
19
+ connection: { filename: ":memory:" },
20
+ useNullAsDefault: true
21
+ });
22
+ t.after(() => knex.destroy());
23
+ await knex.schema.createTable("books", (table) => {
24
+ table.integer("id").primary();
25
+ table.integer("workspace_id").notNullable();
26
+ table.string("name").notNullable();
27
+ table.dateTime("created_at").notNullable();
28
+ });
29
+ const rows = Array.from({ length: 410 }, (_, index) => ({
30
+ id: index + 1,
31
+ workspace_id: index % 2 + 1,
32
+ name: `Book ${index + 1}`,
33
+ created_at: new Date(Date.UTC(2026, 8, 1, 0, 0, Math.floor(index / 6)))
34
+ }));
35
+ await knex.batchInsert("books", rows, 100);
36
+
37
+ const resource = defineCrudResource({
38
+ namespace: "books",
39
+ tableName: "books",
40
+ autofilter: "workspace",
41
+ defaultSort: ["-createdAt"],
42
+ crudOperations: ["list"],
43
+ schema: {
44
+ id: { type: "id", primary: true },
45
+ workspaceId: { type: "id", column: "workspace_id" },
46
+ name: {
47
+ type: "string",
48
+ operations: { output: { required: true } }
49
+ },
50
+ createdAt: { type: "dateTime", temporalPrecision: 3, column: "created_at" }
51
+ }
52
+ });
53
+ const api = await createJsonRestApiHost({ knex });
54
+ await addResourceIfMissing(api, "books", createJsonRestResourceScopeOptions(resource));
55
+ const repository = createCrudJsonApiRepository({ api, knex, resource, resourceScopeName: "books" });
56
+ const service = createCrudJsonApiService({ repository });
57
+ const actions = createActionCatalogue();
58
+ actions.register({
59
+ contributorId: "test.books",
60
+ domain: "books",
61
+ actions: createCrudJsonApiActions({
62
+ namespace: "books",
63
+ resource,
64
+ service,
65
+ surface: "admin",
66
+ operations: ["list"],
67
+ permissionForOperation: () => ({ require: "all", permissions: ["books.list"] })
68
+ })
69
+ });
70
+ const catalog = createServiceToolCatalog(actions, { maxDirectTools: 0 });
71
+ const context = {
72
+ actor: { id: "7" },
73
+ permissions: ["books.list"],
74
+ surface: "admin",
75
+ scopeValues: { workspaceId: "1" }
76
+ };
77
+ const toolSet = catalog.resolveToolSet(context);
78
+ const search = await catalog.executeToolCall({
79
+ toolName: "assistant_action_search",
80
+ argumentsText: JSON.stringify({ query: "books list" }),
81
+ context,
82
+ toolSet
83
+ });
84
+ assert.equal(search.ok, true);
85
+ assert.deepEqual(search.result.items.map((item) => item.actionId), ["crud.books.list"]);
86
+ const contract = await catalog.executeToolCall({
87
+ toolName: "assistant_action_contract",
88
+ argumentsText: JSON.stringify({ actionId: "crud.books.list", version: 1 }),
89
+ context,
90
+ toolSet
91
+ });
92
+ assert.equal(contract.ok, true);
93
+ const expectedIds = await knex("books")
94
+ .where("workspace_id", 1)
95
+ .orderBy("created_at", "desc")
96
+ .orderBy("id", "asc")
97
+ .pluck("id");
98
+
99
+ for (const limit of [100, 200]) {
100
+ await t.test(`requested limit ${limit}`, async () => {
101
+ const ids = [];
102
+ const cursors = new Set();
103
+ const pageSizes = [];
104
+ let cursor = null;
105
+ for (let page = 0; page < 4; page++) {
106
+ const response = await catalog.executeToolCall({
107
+ toolName: "assistant_action_execute",
108
+ argumentsText: JSON.stringify({
109
+ actionId: "crud.books.list",
110
+ version: 1,
111
+ input: {
112
+ fields: { books: ["id", "name"] },
113
+ limit,
114
+ ...(cursor ? { cursor } : {})
115
+ }
116
+ }),
117
+ context,
118
+ toolSet
119
+ });
120
+ assert.equal(response.ok, true, JSON.stringify(response));
121
+ const result = response.result.result;
122
+ pageSizes.push(result.items.length);
123
+ for (const item of result.items) {
124
+ assert.deepEqual(Object.keys(item).sort(), ["id", "name"]);
125
+ assert.equal(item.name, `Book ${item.id}`);
126
+ ids.push(item.id);
127
+ }
128
+ cursor = result.nextCursor;
129
+ if (cursor === null) break;
130
+ assert.equal(typeof cursor, "string");
131
+ assert.equal(cursors.has(cursor), false, "Each page must advance its cursor");
132
+ cursors.add(cursor);
133
+ }
134
+ assert.equal(cursor, null, "Traversal must reach the end");
135
+ assert.deepEqual(pageSizes, [100, 100, 5]);
136
+ assert.deepEqual(ids, expectedIds.map(String));
137
+ assert.equal(new Set(ids).size, 205);
138
+ });
139
+ }
140
+ });