@ontrails/store 1.0.0-beta.14 → 1.0.0-beta.15

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.
Files changed (92) hide show
  1. package/.turbo/turbo-lint.log +1 -1
  2. package/CHANGELOG.md +7 -0
  3. package/README.md +126 -61
  4. package/dist/index.d.ts +2 -2
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +1 -1
  7. package/dist/index.js.map +1 -1
  8. package/dist/internal/signal-identity.d.ts +17 -0
  9. package/dist/internal/signal-identity.d.ts.map +1 -0
  10. package/dist/internal/signal-identity.js +81 -0
  11. package/dist/internal/signal-identity.js.map +1 -0
  12. package/dist/jsonfile/index.d.ts +3 -0
  13. package/dist/jsonfile/index.d.ts.map +1 -0
  14. package/dist/jsonfile/index.js +2 -0
  15. package/dist/jsonfile/index.js.map +1 -0
  16. package/dist/jsonfile/runtime.d.ts +19 -0
  17. package/dist/jsonfile/runtime.d.ts.map +1 -0
  18. package/dist/jsonfile/runtime.js +403 -0
  19. package/dist/jsonfile/runtime.js.map +1 -0
  20. package/dist/jsonfile/types.d.ts +40 -0
  21. package/dist/jsonfile/types.d.ts.map +1 -0
  22. package/dist/{drizzle → jsonfile}/types.js.map +1 -1
  23. package/dist/store.d.ts +8 -18
  24. package/dist/store.d.ts.map +1 -1
  25. package/dist/store.js +152 -94
  26. package/dist/store.js.map +1 -1
  27. package/dist/testing.d.ts +28 -0
  28. package/dist/testing.d.ts.map +1 -0
  29. package/dist/testing.js +90 -0
  30. package/dist/testing.js.map +1 -0
  31. package/dist/trails/crud.d.ts +38 -0
  32. package/dist/trails/crud.d.ts.map +1 -0
  33. package/dist/trails/crud.js +112 -0
  34. package/dist/trails/crud.js.map +1 -0
  35. package/dist/trails/index.d.ts +7 -0
  36. package/dist/trails/index.d.ts.map +1 -0
  37. package/dist/trails/index.js +4 -0
  38. package/dist/trails/index.js.map +1 -0
  39. package/dist/trails/reconcile.d.ts +36 -0
  40. package/dist/trails/reconcile.d.ts.map +1 -0
  41. package/dist/trails/reconcile.js +142 -0
  42. package/dist/trails/reconcile.js.map +1 -0
  43. package/dist/trails/sync.d.ts +25 -0
  44. package/dist/trails/sync.d.ts.map +1 -0
  45. package/dist/trails/sync.js +96 -0
  46. package/dist/trails/sync.js.map +1 -0
  47. package/dist/trails/utils.d.ts +51 -0
  48. package/dist/trails/utils.d.ts.map +1 -0
  49. package/dist/trails/utils.js +65 -0
  50. package/dist/trails/utils.js.map +1 -0
  51. package/dist/types.d.ts +205 -35
  52. package/dist/types.d.ts.map +1 -1
  53. package/package.json +6 -9
  54. package/src/__tests__/crud.test.ts +346 -0
  55. package/src/__tests__/jsonfile.test.ts +502 -0
  56. package/src/__tests__/store.test.ts +239 -33
  57. package/src/__tests__/sync-reconcile.test.ts +646 -0
  58. package/src/index.ts +12 -8
  59. package/src/internal/signal-identity.ts +162 -0
  60. package/src/jsonfile/index.ts +6 -0
  61. package/src/jsonfile/runtime.ts +702 -0
  62. package/src/jsonfile/types.ts +50 -0
  63. package/src/store.ts +296 -134
  64. package/src/testing.ts +175 -0
  65. package/src/trails/crud.ts +355 -0
  66. package/src/trails/index.ts +10 -0
  67. package/src/trails/reconcile.ts +281 -0
  68. package/src/trails/sync.ts +251 -0
  69. package/src/trails/utils.ts +96 -0
  70. package/src/types.ts +355 -63
  71. package/tsconfig.tests.json +10 -0
  72. package/tsconfig.tsbuildinfo +1 -1
  73. package/dist/drizzle/index.d.ts +0 -3
  74. package/dist/drizzle/index.d.ts.map +0 -1
  75. package/dist/drizzle/index.js +0 -2
  76. package/dist/drizzle/index.js.map +0 -1
  77. package/dist/drizzle/runtime.d.ts +0 -21
  78. package/dist/drizzle/runtime.d.ts.map +0 -1
  79. package/dist/drizzle/runtime.js +0 -458
  80. package/dist/drizzle/runtime.js.map +0 -1
  81. package/dist/drizzle/schema.d.ts +0 -15
  82. package/dist/drizzle/schema.d.ts.map +0 -1
  83. package/dist/drizzle/schema.js +0 -322
  84. package/dist/drizzle/schema.js.map +0 -1
  85. package/dist/drizzle/types.d.ts +0 -40
  86. package/dist/drizzle/types.d.ts.map +0 -1
  87. package/src/drizzle/__tests__/drizzle.test.ts +0 -469
  88. package/src/drizzle/index.ts +0 -17
  89. package/src/drizzle/runtime.ts +0 -853
  90. package/src/drizzle/schema.ts +0 -577
  91. package/src/drizzle/types.ts +0 -70
  92. /package/dist/{drizzle → jsonfile}/types.js +0 -0
package/src/testing.ts ADDED
@@ -0,0 +1,175 @@
1
+ import { expect } from 'bun:test';
2
+
3
+ import type {
4
+ AnyStoreTable,
5
+ EntityOf,
6
+ FiltersOf,
7
+ StoreAccessor,
8
+ StoreIdentifierOf,
9
+ UpsertOf,
10
+ } from './types.js';
11
+
12
+ export interface StoreAccessorContractSubject<TTable extends AnyStoreTable> {
13
+ readonly accessor: StoreAccessor<TTable>;
14
+ readonly dispose?: () => Promise<void> | void;
15
+ }
16
+
17
+ export interface StoreAccessorContractOptions<TTable extends AnyStoreTable> {
18
+ readonly createInput: () => UpsertOf<TTable>;
19
+ readonly createSubject:
20
+ | (() => StoreAccessorContractSubject<TTable>)
21
+ | (() => Promise<StoreAccessorContractSubject<TTable>>);
22
+ readonly expectCreated:
23
+ | ((entity: EntityOf<TTable>, input: UpsertOf<TTable>) => void)
24
+ | ((entity: EntityOf<TTable>, input: UpsertOf<TTable>) => Promise<void>);
25
+ readonly expectUpdated:
26
+ | ((
27
+ entity: EntityOf<TTable>,
28
+ previous: EntityOf<TTable>,
29
+ input: UpsertOf<TTable>
30
+ ) => void)
31
+ | ((
32
+ entity: EntityOf<TTable>,
33
+ previous: EntityOf<TTable>,
34
+ input: UpsertOf<TTable>
35
+ ) => Promise<void>);
36
+ readonly missingId: StoreIdentifierOf<TTable>;
37
+ readonly seedExisting?:
38
+ | ((accessor: StoreAccessor<TTable>) => Promise<EntityOf<TTable>>)
39
+ | ((accessor: StoreAccessor<TTable>) => EntityOf<TTable>);
40
+ readonly table: TTable;
41
+ readonly updateInput: (existing: EntityOf<TTable>) => UpsertOf<TTable>;
42
+ }
43
+
44
+ export interface StoreAccessorContractCase {
45
+ readonly name: string;
46
+ readonly run: () => Promise<void>;
47
+ }
48
+
49
+ const listByIdentity = async <TTable extends AnyStoreTable>(
50
+ table: TTable,
51
+ accessor: StoreAccessor<TTable>,
52
+ entity: EntityOf<TTable>
53
+ ): Promise<readonly EntityOf<TTable>[]> => {
54
+ const identity = table.identity as keyof EntityOf<TTable> & string;
55
+ const filters = {
56
+ [identity]: entity[identity],
57
+ } as FiltersOf<TTable>;
58
+
59
+ return await accessor.list(filters);
60
+ };
61
+
62
+ const withSubject = async <TTable extends AnyStoreTable, TResult>(
63
+ createSubject: StoreAccessorContractOptions<TTable>['createSubject'],
64
+ run: (subject: StoreAccessorContractSubject<TTable>) => Promise<TResult>
65
+ ): Promise<TResult> => {
66
+ const subject = await createSubject();
67
+
68
+ try {
69
+ return await run(subject);
70
+ } finally {
71
+ await subject.dispose?.();
72
+ }
73
+ };
74
+
75
+ const seedExistingEntity = async <TTable extends AnyStoreTable>(
76
+ options: StoreAccessorContractOptions<TTable>,
77
+ accessor: StoreAccessor<TTable>
78
+ ): Promise<EntityOf<TTable>> => {
79
+ if (options.seedExisting !== undefined) {
80
+ return await options.seedExisting(accessor);
81
+ }
82
+
83
+ return await accessor.upsert(options.createInput());
84
+ };
85
+
86
+ /**
87
+ * Shared contract cases for connector-agnostic writable store accessors.
88
+ *
89
+ * Connectors can register these with their own `test(...)` wrappers so the
90
+ * baseline `get/list/upsert/remove` contract stays aligned across runtimes
91
+ * without fighting repository-specific test-lint rules.
92
+ */
93
+ export const createStoreAccessorContractCases = <TTable extends AnyStoreTable>(
94
+ options: StoreAccessorContractOptions<TTable>
95
+ ): readonly StoreAccessorContractCase[] =>
96
+ [
97
+ {
98
+ name: 'upsert creates an entity and exposes it through get/list',
99
+ run: async () => {
100
+ await withSubject(options.createSubject, async ({ accessor }) => {
101
+ const input = options.createInput();
102
+ const created = await accessor.upsert(input);
103
+
104
+ await options.expectCreated(created, input);
105
+ expect(
106
+ await accessor.get(
107
+ created[
108
+ options.table.identity as keyof EntityOf<TTable> & string
109
+ ] as StoreIdentifierOf<TTable>
110
+ )
111
+ ).toEqual(created);
112
+ expect(
113
+ await listByIdentity(options.table, accessor, created)
114
+ ).toEqual([created]);
115
+ });
116
+ },
117
+ },
118
+ {
119
+ name: 'upsert updates an existing entity in place when the identity matches',
120
+ run: async () => {
121
+ await withSubject(options.createSubject, async ({ accessor }) => {
122
+ const existing = await seedExistingEntity(options, accessor);
123
+ const input = options.updateInput(existing);
124
+ const updated = await accessor.upsert(input);
125
+ const identity = options.table.identity as keyof EntityOf<TTable> &
126
+ string;
127
+
128
+ expect(updated[identity]).toBe(existing[identity]);
129
+ await options.expectUpdated(updated, existing, input);
130
+ expect(
131
+ await accessor.get(updated[identity] as StoreIdentifierOf<TTable>)
132
+ ).toEqual(updated);
133
+ expect(
134
+ await listByIdentity(options.table, accessor, updated)
135
+ ).toEqual([updated]);
136
+ });
137
+ },
138
+ },
139
+ {
140
+ name: 'remove deletes an existing entity',
141
+ run: async () => {
142
+ await withSubject(options.createSubject, async ({ accessor }) => {
143
+ const existing = await seedExistingEntity(options, accessor);
144
+ const identity = options.table.identity as keyof EntityOf<TTable> &
145
+ string;
146
+ const removed = await accessor.remove(
147
+ existing[identity] as StoreIdentifierOf<TTable>
148
+ );
149
+
150
+ expect(removed).toEqual({ deleted: true });
151
+ expect(
152
+ await accessor.get(existing[identity] as StoreIdentifierOf<TTable>)
153
+ ).toBeNull();
154
+ });
155
+ },
156
+ },
157
+ {
158
+ name: 'get returns null for a missing identity',
159
+ run: async () => {
160
+ await withSubject(options.createSubject, async ({ accessor }) => {
161
+ expect(await accessor.get(options.missingId)).toBeNull();
162
+ });
163
+ },
164
+ },
165
+ {
166
+ name: 'remove reports false when the identity is missing',
167
+ run: async () => {
168
+ await withSubject(options.createSubject, async ({ accessor }) => {
169
+ expect(await accessor.remove(options.missingId)).toEqual({
170
+ deleted: false,
171
+ });
172
+ });
173
+ },
174
+ },
175
+ ] as const;
@@ -0,0 +1,355 @@
1
+ import type { Implementation, Resource, Trail } from '@ontrails/core';
2
+ import { deriveTrail } from '@ontrails/core/trails';
3
+ import type {
4
+ DeriveTrailInput,
5
+ DeriveTrailOutput,
6
+ } from '@ontrails/core/trails';
7
+ import type { z } from 'zod';
8
+
9
+ import type {
10
+ AnyStoreTable,
11
+ EntityOf,
12
+ FiltersOf,
13
+ InsertOf,
14
+ StoreAccessor,
15
+ StoreIdentifierOf,
16
+ UpdateOf,
17
+ } from '../types.js';
18
+ import { createTableContour } from './utils.js';
19
+ import type { TableContour } from './utils.js';
20
+
21
+ type IdentityInputOf<TTable extends AnyStoreTable> = Readonly<
22
+ Record<Extract<TTable['identity'], string>, StoreIdentifierOf<TTable>>
23
+ >;
24
+
25
+ type CrudConnection<TTable extends AnyStoreTable> = Readonly<
26
+ Record<TTable['name'], StoreAccessor<TTable>>
27
+ >;
28
+
29
+ type TableContourFieldKey<TTable extends AnyStoreTable> = Extract<
30
+ keyof z.output<TableContour<TTable>>,
31
+ string
32
+ >;
33
+
34
+ type GeneratedFieldsOf<TTable extends AnyStoreTable> =
35
+ TTable['generated'] extends readonly TableContourFieldKey<TTable>[]
36
+ ? TTable['generated']
37
+ : readonly [];
38
+
39
+ /**
40
+ * Input type `deriveTrail` projects for a given CRUD operation against a
41
+ * store table. Routes through `TableContour<TTable>` so the projected input
42
+ * structurally matches the contour-backed derivation path in
43
+ * `@ontrails/core`'s `deriveTrail`.
44
+ */
45
+ type DerivedInput<
46
+ TTable extends AnyStoreTable,
47
+ TOperation extends 'create' | 'read' | 'update' | 'delete' | 'list',
48
+ > = DeriveTrailInput<
49
+ TableContour<TTable>,
50
+ TOperation,
51
+ GeneratedFieldsOf<TTable>
52
+ >;
53
+
54
+ /**
55
+ * Output type `deriveTrail` projects for a given CRUD operation against a
56
+ * store table.
57
+ */
58
+ type DerivedOutput<
59
+ TTable extends AnyStoreTable,
60
+ TOperation extends 'create' | 'read' | 'update' | 'delete' | 'list',
61
+ > = DeriveTrailOutput<TableContour<TTable>, TOperation>;
62
+
63
+ type InternalCreateTrailOf<TTable extends AnyStoreTable> = Trail<
64
+ DerivedInput<TTable, 'create'>,
65
+ DerivedOutput<TTable, 'create'>
66
+ >;
67
+
68
+ type InternalReadTrailOf<TTable extends AnyStoreTable> = Trail<
69
+ DerivedInput<TTable, 'read'>,
70
+ DerivedOutput<TTable, 'read'>
71
+ >;
72
+
73
+ type InternalUpdateTrailOf<TTable extends AnyStoreTable> = Trail<
74
+ DerivedInput<TTable, 'update'>,
75
+ DerivedOutput<TTable, 'update'>
76
+ >;
77
+
78
+ type InternalDeleteTrailOf<TTable extends AnyStoreTable> = Trail<
79
+ DerivedInput<TTable, 'delete'>,
80
+ DerivedOutput<TTable, 'delete'>
81
+ >;
82
+
83
+ type InternalListTrailOf<TTable extends AnyStoreTable> = Trail<
84
+ DerivedInput<TTable, 'list'>,
85
+ DerivedOutput<TTable, 'list'>
86
+ >;
87
+
88
+ type InternalCrudBaseTrails<TTable extends AnyStoreTable> = Readonly<{
89
+ createBase: InternalCreateTrailOf<TTable>;
90
+ readBase: InternalReadTrailOf<TTable>;
91
+ updateBase: InternalUpdateTrailOf<TTable>;
92
+ deleteBase: InternalDeleteTrailOf<TTable>;
93
+ listBase: InternalListTrailOf<TTable>;
94
+ }>;
95
+
96
+ type TrailExampleOf<TInput, TOutput> = NonNullable<
97
+ Trail<TInput, TOutput>['examples']
98
+ >[number];
99
+
100
+ type CreateTrailOf<TTable extends AnyStoreTable> = Trail<
101
+ InsertOf<TTable>,
102
+ EntityOf<TTable>
103
+ >;
104
+
105
+ type ReadTrailOf<TTable extends AnyStoreTable> = Trail<
106
+ IdentityInputOf<TTable>,
107
+ EntityOf<TTable>
108
+ >;
109
+
110
+ type UpdateTrailOf<TTable extends AnyStoreTable> = Trail<
111
+ IdentityInputOf<TTable> & UpdateOf<TTable>,
112
+ EntityOf<TTable>
113
+ >;
114
+
115
+ type DeleteTrailOf<TTable extends AnyStoreTable> = Trail<
116
+ IdentityInputOf<TTable>,
117
+ undefined
118
+ >;
119
+
120
+ type ListTrailOf<TTable extends AnyStoreTable> = Trail<
121
+ FiltersOf<TTable>,
122
+ EntityOf<TTable>[]
123
+ >;
124
+
125
+ type InternalCrudTrails<TTable extends AnyStoreTable> = readonly [
126
+ create: InternalCreateTrailOf<TTable>,
127
+ read: InternalReadTrailOf<TTable>,
128
+ update: InternalUpdateTrailOf<TTable>,
129
+ remove: InternalDeleteTrailOf<TTable>,
130
+ list: InternalListTrailOf<TTable>,
131
+ ];
132
+
133
+ export type CrudTrails<TTable extends AnyStoreTable> = readonly [
134
+ create: CreateTrailOf<TTable>,
135
+ read: ReadTrailOf<TTable>,
136
+ update: UpdateTrailOf<TTable>,
137
+ remove: DeleteTrailOf<TTable>,
138
+ list: ListTrailOf<TTable>,
139
+ ];
140
+
141
+ export interface CrudBlazeOverrides<TTable extends AnyStoreTable> {
142
+ readonly create?: Implementation<InsertOf<TTable>, EntityOf<TTable>>;
143
+ readonly read?: Implementation<IdentityInputOf<TTable>, EntityOf<TTable>>;
144
+ readonly update?: Implementation<
145
+ IdentityInputOf<TTable> & UpdateOf<TTable>,
146
+ EntityOf<TTable>
147
+ >;
148
+ readonly delete?: Implementation<IdentityInputOf<TTable>, undefined>;
149
+ readonly list?: Implementation<FiltersOf<TTable>, EntityOf<TTable>[]>;
150
+ }
151
+
152
+ export interface CrudOptions<TTable extends AnyStoreTable> {
153
+ readonly blaze?: CrudBlazeOverrides<TTable>;
154
+ }
155
+
156
+ interface InternalCrudBlazeOverrides<TTable extends AnyStoreTable> {
157
+ readonly create?: Implementation<
158
+ DerivedInput<TTable, 'create'>,
159
+ DerivedOutput<TTable, 'create'>
160
+ >;
161
+ readonly read?: Implementation<
162
+ DerivedInput<TTable, 'read'>,
163
+ DerivedOutput<TTable, 'read'>
164
+ >;
165
+ readonly update?: Implementation<
166
+ DerivedInput<TTable, 'update'>,
167
+ DerivedOutput<TTable, 'update'>
168
+ >;
169
+ readonly delete?: Implementation<
170
+ DerivedInput<TTable, 'delete'>,
171
+ DerivedOutput<TTable, 'delete'>
172
+ >;
173
+ readonly list?: Implementation<
174
+ DerivedInput<TTable, 'list'>,
175
+ DerivedOutput<TTable, 'list'>
176
+ >;
177
+ }
178
+
179
+ interface InternalCrudOptions<TTable extends AnyStoreTable> {
180
+ readonly blaze?: InternalCrudBlazeOverrides<TTable>;
181
+ }
182
+
183
+ const normalizeExampleForOutput = <TInput, TOutput>(
184
+ example: TrailExampleOf<TInput, TOutput>,
185
+ output: z.ZodType<TOutput>
186
+ ): TrailExampleOf<TInput, TOutput> | undefined => {
187
+ if (example.expected === undefined) {
188
+ return example;
189
+ }
190
+
191
+ const parsed = output.safeParse(example.expected);
192
+ return parsed.success
193
+ ? {
194
+ ...example,
195
+ expected: parsed.data,
196
+ }
197
+ : undefined;
198
+ };
199
+
200
+ const normalizeExamplesForOutput = <TInput, TOutput>(
201
+ base: Trail<TInput, TOutput>,
202
+ output: z.ZodType<TOutput>
203
+ ): Trail<TInput, TOutput>['examples'] => {
204
+ const { examples } = base;
205
+ if (examples === undefined || examples.length === 0) {
206
+ return undefined;
207
+ }
208
+
209
+ const next = examples
210
+ .map((example) => normalizeExampleForOutput(example, output))
211
+ .filter(
212
+ (example): example is TrailExampleOf<TInput, TOutput> =>
213
+ example !== undefined
214
+ );
215
+
216
+ return next.length === 0
217
+ ? undefined
218
+ : (Object.freeze(next) as Trail<TInput, TOutput>['examples']);
219
+ };
220
+
221
+ const finalizeTrail = <TInput, TOutput>(
222
+ base: Trail<TInput, TOutput>,
223
+ options: {
224
+ readonly blaze?: Implementation<TInput, TOutput> | undefined;
225
+ readonly output?: z.ZodType<TOutput> | undefined;
226
+ readonly pattern?: string | undefined;
227
+ } = {}
228
+ ): Trail<TInput, TOutput> =>
229
+ Object.freeze({
230
+ ...base,
231
+ ...(options.blaze === undefined ? {} : { blaze: options.blaze }),
232
+ ...(options.output === undefined
233
+ ? {}
234
+ : {
235
+ examples: normalizeExamplesForOutput(base, options.output),
236
+ output: options.output,
237
+ }),
238
+ ...(options.pattern === undefined ? {} : { pattern: options.pattern }),
239
+ }) as Trail<TInput, TOutput>;
240
+
241
+ const deriveCrudBaseTrails = <
242
+ TTable extends AnyStoreTable,
243
+ TConnection extends CrudConnection<TTable>,
244
+ >(
245
+ table: TTable,
246
+ resource: Resource<TConnection>
247
+ ): InternalCrudBaseTrails<TTable> => {
248
+ const entityContour = createTableContour(table);
249
+ // Narrow the store's `readonly string[]` to the contour's typed field-key
250
+ // array so `deriveTrail`'s `TGenerated` generic picks up the precise
251
+ // key-of shape that `CreateInputOf<Contour, TGenerated>` expects. The
252
+ // runtime value is unchanged — the names in `table.generated` are already
253
+ // keys of `table.schema.shape` by construction in `store()`.
254
+ const generated = table.generated as GeneratedFieldsOf<TTable>;
255
+
256
+ return {
257
+ createBase: deriveTrail(entityContour, 'create', {
258
+ generated,
259
+ resource,
260
+ }),
261
+ deleteBase: deriveTrail(entityContour, 'delete', {
262
+ resource,
263
+ }),
264
+ listBase: deriveTrail(entityContour, 'list', {
265
+ resource,
266
+ }),
267
+ readBase: deriveTrail(entityContour, 'read', {
268
+ resource,
269
+ }),
270
+ // The `update` blaze synthesized by `deriveTrail` handles the partial-patch
271
+ // concern: when the accessor lacks a native `update`, the fallback path in
272
+ // `derive-trail.ts` (`updateViaReadAndUpsert`) reads the current entity,
273
+ // merges the patch, strips the `version` field, then calls `upsert` with
274
+ // the full merged payload — so no fields are silently lost.
275
+ updateBase: deriveTrail(entityContour, 'update', {
276
+ generated,
277
+ resource,
278
+ }),
279
+ };
280
+ };
281
+
282
+ const buildCrudTrails = <TTable extends AnyStoreTable>(
283
+ baseTrails: InternalCrudBaseTrails<TTable>,
284
+ overrides: InternalCrudBlazeOverrides<TTable>,
285
+ entityOutput: z.ZodType<DerivedOutput<TTable, 'create'>>,
286
+ listOutput: z.ZodType<DerivedOutput<TTable, 'list'>>
287
+ ): InternalCrudTrails<TTable> =>
288
+ Object.freeze([
289
+ finalizeTrail(baseTrails.createBase, {
290
+ ...(overrides.create === undefined ? {} : { blaze: overrides.create }),
291
+ output: entityOutput,
292
+ pattern: 'crud',
293
+ }),
294
+ finalizeTrail(baseTrails.readBase, {
295
+ ...(overrides.read === undefined ? {} : { blaze: overrides.read }),
296
+ output: entityOutput,
297
+ pattern: 'crud',
298
+ }),
299
+ finalizeTrail(baseTrails.updateBase, {
300
+ ...(overrides.update === undefined ? {} : { blaze: overrides.update }),
301
+ output: entityOutput,
302
+ pattern: 'crud',
303
+ }),
304
+ overrides.delete === undefined
305
+ ? finalizeTrail(baseTrails.deleteBase, { pattern: 'crud' })
306
+ : finalizeTrail(baseTrails.deleteBase, {
307
+ blaze: overrides.delete,
308
+ pattern: 'crud',
309
+ }),
310
+ finalizeTrail(baseTrails.listBase, {
311
+ ...(overrides.list === undefined ? {} : { blaze: overrides.list }),
312
+ output: listOutput,
313
+ pattern: 'crud',
314
+ }),
315
+ ]) as InternalCrudTrails<TTable>;
316
+
317
+ /**
318
+ * Produce the standard CRUD trail tuple for one normalized store table.
319
+ *
320
+ * The factory derives schemas, examples, resources, and contour linkage from
321
+ * the table metadata. Blazes default to the connector-agnostic store accessor
322
+ * contract via `deriveTrail()`'s single-resource synthesis path. Per-operation
323
+ * blaze overrides stay available for callers that need custom persistence
324
+ * behavior and are layered onto the derived trails in a single pass.
325
+ */
326
+ export function crud<
327
+ TTable extends AnyStoreTable,
328
+ TConnection extends CrudConnection<TTable>,
329
+ >(
330
+ table: TTable,
331
+ resource: Resource<TConnection>,
332
+ options?: CrudOptions<TTable>
333
+ ): CrudTrails<TTable>;
334
+ export function crud<
335
+ TTable extends AnyStoreTable,
336
+ TConnection extends CrudConnection<TTable>,
337
+ >(
338
+ table: TTable,
339
+ resource: Resource<TConnection>,
340
+ options: InternalCrudOptions<TTable> = {}
341
+ ) {
342
+ const overrides = options.blaze ?? {};
343
+ const baseTrails = deriveCrudBaseTrails(table, resource);
344
+ // Narrow `table.schema` (typed `StoreObjectSchema`, which is
345
+ // `z.ZodObject<Record<string, z.ZodType>>`) to a ZodObject keyed by the
346
+ // concrete shape so its `z.output` unifies with the contour-derived
347
+ // output. Structurally `table.schema` already has `shape:
348
+ // TTable['schema']['shape']` — this only refines the generic parameter.
349
+ const entitySchema = table.schema as z.ZodObject<TTable['schema']['shape']>;
350
+ const entityOutput: z.ZodType<DerivedOutput<TTable, 'create'>> = entitySchema;
351
+ const listOutput: z.ZodType<DerivedOutput<TTable, 'list'>> =
352
+ entitySchema.array();
353
+
354
+ return buildCrudTrails(baseTrails, overrides, entityOutput, listOutput);
355
+ }
@@ -0,0 +1,10 @@
1
+ export { crud } from './crud.js';
2
+ export type { CrudBlazeOverrides, CrudOptions, CrudTrails } from './crud.js';
3
+ export { reconcile } from './reconcile.js';
4
+ export type {
5
+ ReconcileConflict,
6
+ ReconcileOptions,
7
+ ReconcileStrategy,
8
+ } from './reconcile.js';
9
+ export { sync } from './sync.js';
10
+ export type { SyncEndpoint, SyncOptions, SyncTransform } from './sync.js';