on-zero 0.9.7 → 0.10.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.
Files changed (49) hide show
  1. package/dist/cjs/generate-helpers.test.cjs +0 -38
  2. package/dist/cjs/generate-helpers.test.native.js +0 -38
  3. package/dist/cjs/generate-helpers.test.native.js.map +1 -1
  4. package/dist/cjs/generate-lite.test.cjs +0 -522
  5. package/dist/cjs/generate-lite.test.native.js +0 -525
  6. package/dist/cjs/generate-lite.test.native.js.map +1 -1
  7. package/dist/cjs/generate.test.cjs +0 -691
  8. package/dist/cjs/generate.test.native.js +0 -691
  9. package/dist/cjs/generate.test.native.js.map +1 -1
  10. package/dist/cjs/mutations.test.cjs +0 -11
  11. package/dist/cjs/mutations.test.native.js +0 -18
  12. package/dist/cjs/mutations.test.native.js.map +1 -1
  13. package/dist/cjs/server.test.cjs +0 -93
  14. package/dist/cjs/server.test.native.js +0 -101
  15. package/dist/cjs/server.test.native.js.map +1 -1
  16. package/dist/cjs/serverWhere.test.cjs +0 -45
  17. package/dist/cjs/serverWhere.test.native.js +0 -51
  18. package/dist/cjs/serverWhere.test.native.js.map +1 -1
  19. package/dist/esm/generate-helpers.test.mjs +1 -39
  20. package/dist/esm/generate-helpers.test.mjs.map +1 -1
  21. package/dist/esm/generate-helpers.test.native.js +1 -39
  22. package/dist/esm/generate-helpers.test.native.js.map +1 -1
  23. package/dist/esm/generate-lite.test.mjs +0 -522
  24. package/dist/esm/generate-lite.test.mjs.map +1 -1
  25. package/dist/esm/generate-lite.test.native.js +0 -525
  26. package/dist/esm/generate-lite.test.native.js.map +1 -1
  27. package/dist/esm/generate.test.mjs +2 -668
  28. package/dist/esm/generate.test.mjs.map +1 -1
  29. package/dist/esm/generate.test.native.js +2 -668
  30. package/dist/esm/generate.test.native.js.map +1 -1
  31. package/dist/esm/mutations.test.mjs +0 -11
  32. package/dist/esm/mutations.test.mjs.map +1 -1
  33. package/dist/esm/mutations.test.native.js +0 -18
  34. package/dist/esm/mutations.test.native.js.map +1 -1
  35. package/dist/esm/server.test.mjs +0 -93
  36. package/dist/esm/server.test.mjs.map +1 -1
  37. package/dist/esm/server.test.native.js +0 -101
  38. package/dist/esm/server.test.native.js.map +1 -1
  39. package/dist/esm/serverWhere.test.mjs +0 -45
  40. package/dist/esm/serverWhere.test.mjs.map +1 -1
  41. package/dist/esm/serverWhere.test.native.js +0 -51
  42. package/dist/esm/serverWhere.test.native.js.map +1 -1
  43. package/package.json +1 -1
  44. package/src/generate-helpers.test.ts +0 -40
  45. package/src/generate-lite.test.ts +0 -586
  46. package/src/generate.test.ts +0 -844
  47. package/src/mutations.test.ts +0 -21
  48. package/src/server.test.ts +0 -75
  49. package/src/serverWhere.test.ts +0 -42
@@ -4,27 +4,6 @@ import { mutations } from './mutations'
4
4
  import { serverWhere } from './serverWhere'
5
5
 
6
6
  describe('mutations registry', () => {
7
- test('two modules registering the same table keep both custom mutators', () => {
8
- // a template commonly splits a table's mutators across files (the table's
9
- // own mutations file plus a seed.ts firing a demo seed on that table).
10
- // the registry is keyed by table, so a wholesale replace made whichever
11
- // module imported LAST win: alphabetical import order silently dropped
12
- // seed.ts's seedDemo whenever the seed file sorted before the table file.
13
- const permissions = serverWhere('todo', () => true)
14
-
15
- const seedModule = mutations('todo', permissions, {
16
- seedDemo: async () => {},
17
- })
18
- const tableModule = mutations('todo', permissions, {})
19
-
20
- expect(typeof seedModule.seedDemo).toBe('function')
21
- expect(typeof tableModule.insert).toBe('function')
22
- // both proxies read the same per-table registry: the later CRUD-only
23
- // registration must not clobber the earlier custom mutator
24
- expect(typeof (tableModule as Record<string, unknown>).seedDemo).toBe('function')
25
- expect(Object.keys(tableModule)).toContain('seedDemo')
26
- })
27
-
28
7
  test('re-registering a handler replaces it per key (HMR)', () => {
29
8
  const permissions = serverWhere('post', () => true)
30
9
  const v1 = async () => {}
@@ -121,81 +121,6 @@ describe('createZeroServerBindings', () => {
121
121
  expect(rows).toEqual([])
122
122
  })
123
123
 
124
- test('binds auth, queries, pipe keys, effects, and direct execution structurally', async () => {
125
- const rows: ProjectRow[] = []
126
- let mutationRuns = 0
127
- let validatedMutationAuth: string | undefined
128
- let validatedQueryAuth: string | undefined
129
- let barrierRuns = 0
130
- let backgroundRuns = 0
131
- let backgroundAuth: string | undefined
132
-
133
- const bindings = createZeroServerBindings({
134
- schema,
135
- models: {
136
- project: {
137
- mutate: {
138
- create: async (
139
- { authData, server, tx }: MutatorContext,
140
- value: ProjectRow
141
- ) => {
142
- mutationRuns++
143
- expect(authData?.id).toBe('user-1')
144
- await tx.mutate.project.insert(value)
145
- server?.enqueueTask(
146
- async () => {
147
- barrierRuns++
148
- },
149
- { barrier: true }
150
- )
151
- server?.enqueueTask(async () => {
152
- backgroundRuns++
153
- backgroundAuth = getScopedAuthData()?.id as string | undefined
154
- })
155
- },
156
- },
157
- },
158
- },
159
- createServerActions: () => ({}),
160
- queries,
161
- validateMutation({ authData }) {
162
- validatedMutationAuth = authData?.id as string | undefined
163
- },
164
- validateQuery({ authData }) {
165
- validatedQueryAuth = authData?.id as string | undefined
166
- },
167
- })
168
-
169
- expect(Object.keys(bindings.mutators)).toEqual(['project|create'])
170
- const { executor, queryClaims, scheduledBackground } = createTestExecutor(
171
- bindings.mutators,
172
- rows
173
- )
174
- const server = bindings.server(executor)
175
- await server.mutate.project.create(
176
- { id: 'project-1', ownerId: 'user-1', name: 'first' },
177
- { authData: { id: 'user-1' } }
178
- )
179
-
180
- expect(rows).toEqual([{ id: 'project-1', ownerId: 'user-1', name: 'first' }])
181
- expect(mutationRuns).toBe(1)
182
- expect(validatedMutationAuth).toBe('user-1')
183
- expect(barrierRuns).toBe(1)
184
- await Promise.all(scheduledBackground)
185
- expect(backgroundRuns).toBe(1)
186
- expect(backgroundAuth).toBe('user-1')
187
-
188
- const ast = await bindings.resolveQuery('project|byOwner', [{ ownerId: 'user-1' }], {
189
- id: 'user-1',
190
- })
191
- expect(JSON.stringify(ast)).toContain('ownerId')
192
- expect(JSON.stringify(ast)).toContain('user-1')
193
- expect(validatedQueryAuth).toBe('user-1')
194
-
195
- await server.query({ id: 'user-1' }, () => zql.project)
196
- expect(queryClaims).toEqual([{ userID: 'user-1', authData: { id: 'user-1' } }])
197
- })
198
-
199
124
  test('enqueues typed actions through the configured local executor', async () => {
200
125
  type Action =
201
126
  | { type: 'project.provisionNamespace'; projectId: string }
@@ -30,48 +30,6 @@ describe('serverWhere SSR behavior', () => {
30
30
  ;(globalThis as any)[Symbol.for('on-zero:state')] = null
31
31
  })
32
32
 
33
- test('serverWhere returns no-op on client environment', () => {
34
- setEnvironment('client')
35
-
36
- const whereFn = serverWhere('post', (eb) => eb.cmp('ownerId', 'user-123'))
37
- const eb = createMockEB()
38
- const result = whereFn(eb as any, { id: 'user-123' })
39
-
40
- // on client, should return no-op (and())
41
- expect(eb.calls).toContain('and()')
42
- expect(result).toEqual({ type: 'noop' })
43
- })
44
-
45
- test('serverWhere evaluates condition on server environment', () => {
46
- setEnvironment('server')
47
-
48
- const whereFn = serverWhere('post', (eb) => eb.cmp('ownerId', 'user-123'))
49
- const eb = createMockEB()
50
- const result = whereFn(eb as any, { id: 'user-123' })
51
-
52
- // on server, should evaluate the actual condition
53
- expect(eb.calls).toContain('cmp(ownerId, user-123)')
54
- expect(result).toEqual({ type: 'condition', field: 'ownerId', value: 'user-123' })
55
- })
56
-
57
- test('serverWhere evaluates when _evaluatingPermission is true (even on client)', () => {
58
- setEnvironment('client')
59
-
60
- const whereFn = serverWhere('post', (eb) => eb.cmp('ownerId', 'user-123'))
61
- const eb = createMockEB()
62
-
63
- setEvaluatingPermission(true)
64
- try {
65
- const result = whereFn(eb as any, { id: 'user-123' })
66
-
67
- // even on client, should evaluate when evaluating permission
68
- expect(eb.calls).toContain('cmp(ownerId, user-123)')
69
- expect(result).toEqual({ type: 'condition', field: 'ownerId', value: 'user-123' })
70
- } finally {
71
- setEvaluatingPermission(false)
72
- }
73
- })
74
-
75
33
  test('environment stays server when already set (SSR scenario)', () => {
76
34
  // simulate SSR: server sets environment first
77
35
  setEnvironment('server')