@jskit-ai/crud-core 0.2.0 → 0.2.1

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.2.0",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=24.0.0"
@@ -27,9 +27,9 @@
27
27
  "./locales/en.json": "./locales/en.json"
28
28
  },
29
29
  "dependencies": {
30
- "@jskit-ai/database-runtime": "0.1.249",
31
- "@jskit-ai/json-rest-api-core": "0.2.0",
32
- "@jskit-ai/resource-crud-core": "0.1.191",
30
+ "@jskit-ai/database-runtime": "0.1.250",
31
+ "@jskit-ai/json-rest-api-core": "0.2.1",
32
+ "@jskit-ai/resource-crud-core": "0.1.192",
33
33
  "json-rest-schema": "^1.0.17",
34
34
  "json-rest-api": "2.1.0"
35
35
  },
@@ -50,7 +50,7 @@
50
50
  }
51
51
  },
52
52
  "peerDependencies": {
53
- "@jskit-ai/http-runtime": "0.2.0",
54
- "@jskit-ai/kernel": "0.2.0"
53
+ "@jskit-ai/http-runtime": "0.2.1",
54
+ "@jskit-ai/kernel": "0.2.1"
55
55
  }
56
56
  }
@@ -96,6 +96,13 @@ surface further; do not register unused mutation actions and routes. Use
96
96
  `routes: false` only for an internal
97
97
  capability/action surface that deliberately has no HTTP API.
98
98
 
99
+ Create, update, and delete publish `<namespace>.record.changed` to the
100
+ `event_scope` realtime audience, which reaches only the room of the action's
101
+ user, workspace, or workspace-user scope. Set `realtimeAudience` to another
102
+ realtime audience when the product needs one, for example `"all_users"` so
103
+ every signed-in user's view of a public resource refreshes. It also accepts a
104
+ function of the action execution.
105
+
99
106
  When otherwise-standard CRUD earns product behavior, name the exact
100
107
  capabilities in `requires` and provide `decorateService({ service, repository,
101
108
  resource, ...dependencies })`. Retain the standard methods, override only the
@@ -8,8 +8,8 @@
8
8
  "./shared": "./src/shared/index.js"
9
9
  },
10
10
  "dependencies": {
11
- "@jskit-ai/crud-core": "0.2.0",
12
- "@jskit-ai/resource-crud-core": "0.1.191"
11
+ "@jskit-ai/crud-core": "0.2.1",
12
+ "@jskit-ai/resource-crud-core": "0.1.192"
13
13
  },
14
14
  "jskit": {
15
15
  "kind": "runtime",
@@ -163,7 +163,8 @@ function defineCrudJsonApiFeature({
163
163
  operationLifecycle = {},
164
164
  operationInputs = {},
165
165
  actions = {},
166
- operations = undefined
166
+ operations = undefined,
167
+ realtimeAudience = "event_scope"
167
168
  } = {}) {
168
169
  if (!resource || typeof resource !== "object" || Array.isArray(resource)) {
169
170
  throw new TypeError("defineCrudJsonApiFeature requires resource.");
@@ -301,7 +302,8 @@ function defineCrudJsonApiFeature({
301
302
  permissions: permissionOptions
302
303
  }),
303
304
  scopeInputValidator: normalizedScope.actionInputValidator,
304
- scopeInputKeys: normalizedScope.inputKeys
305
+ scopeInputKeys: normalizedScope.inputKeys,
306
+ realtimeAudience
305
307
  });
306
308
  }
307
309
  });
@@ -558,7 +558,8 @@ function createCrudJsonApiActions({
558
558
  operationLifecycle = {},
559
559
  operationInputs = {},
560
560
  actions: additionalActionDefinitions = {},
561
- dependencies = {}
561
+ dependencies = {},
562
+ realtimeAudience = "event_scope"
562
563
  } = {}) {
563
564
  const actionId = (operation) => `crud.${namespace}.${operation}`;
564
565
  if (!service || typeof service !== "object") {
@@ -580,7 +581,7 @@ function createCrudJsonApiActions({
580
581
  entityId,
581
582
  realtime: {
582
583
  event: recordChangedEvent,
583
- audience: "event_scope"
584
+ audience: realtimeAudience
584
585
  }
585
586
  });
586
587
  const lifecycle = normalizeCrudOperationLifecycle(operationLifecycle);
@@ -150,6 +150,45 @@ test("defineCrudJsonApiFeature composes one resource without ceremonial token la
150
150
  await runtime.shutdown();
151
151
  });
152
152
 
153
+ test("defineCrudJsonApiFeature sends record.changed to its realtime audience", async () => {
154
+ const execution = { input: { recordId: "5" }, result: { data: { id: "5" } }, context: {} };
155
+ for (const [options, audience] of [[{}, "event_scope"], [{ realtimeAudience: "all_users" }, "all_users"]]) {
156
+ let actions;
157
+ const observer = defineProvider({
158
+ id: "test.observer",
159
+ requires: { actions: "runtime.actions", books: "crud.books" },
160
+ setup(dependencies) {
161
+ actions = dependencies.actions;
162
+ return {};
163
+ }
164
+ });
165
+ const runtime = createCapabilityRuntime({
166
+ providers: [
167
+ createActionProvider(),
168
+ ...createFeatureDependencies([]),
169
+ defineCrudJsonApiFeature({
170
+ resource: createBookResource({ apiAccess: "public", autofilter: "public" }),
171
+ surface: "home",
172
+ ...options
173
+ }),
174
+ observer
175
+ ]
176
+ });
177
+ await runtime.start();
178
+
179
+ assert.deepEqual(
180
+ actions.listDefinitions()
181
+ .filter((entry) => entry.events.length > 0)
182
+ .map((entry) => [entry.id, entry.events[0](execution).realtime]),
183
+ ["create", "update", "delete"].map((operation) => [
184
+ `crud.books.${operation}`,
185
+ { event: "books.record.changed", audience }
186
+ ])
187
+ );
188
+ await runtime.shutdown();
189
+ }
190
+ });
191
+
153
192
  test("defineCrudJsonApiFeature makes workspace scope and permissions explicit", async () => {
154
193
  const routes = [];
155
194
  const feature = defineCrudJsonApiFeature({