syncorejs 0.2.1 → 0.2.3

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 (169) hide show
  1. package/README.md +2 -1
  2. package/dist/_vendor/cli/app.d.mts.map +1 -1
  3. package/dist/_vendor/cli/app.mjs +330 -46
  4. package/dist/_vendor/cli/app.mjs.map +1 -1
  5. package/dist/_vendor/cli/context.mjs +27 -9
  6. package/dist/_vendor/cli/context.mjs.map +1 -1
  7. package/dist/_vendor/cli/dev-session.mjs.map +1 -1
  8. package/dist/_vendor/cli/doctor.mjs +513 -46
  9. package/dist/_vendor/cli/doctor.mjs.map +1 -1
  10. package/dist/_vendor/cli/errors.mjs.map +1 -1
  11. package/dist/_vendor/cli/help.mjs.map +1 -1
  12. package/dist/_vendor/cli/index.mjs +9 -2
  13. package/dist/_vendor/cli/index.mjs.map +1 -1
  14. package/dist/_vendor/cli/messages.mjs +5 -4
  15. package/dist/_vendor/cli/messages.mjs.map +1 -1
  16. package/dist/_vendor/cli/preflight.mjs.map +1 -1
  17. package/dist/_vendor/cli/project.mjs +125 -27
  18. package/dist/_vendor/cli/project.mjs.map +1 -1
  19. package/dist/_vendor/cli/render.mjs +57 -9
  20. package/dist/_vendor/cli/render.mjs.map +1 -1
  21. package/dist/_vendor/cli/targets.mjs +4 -3
  22. package/dist/_vendor/cli/targets.mjs.map +1 -1
  23. package/dist/_vendor/core/cli.d.mts +20 -4
  24. package/dist/_vendor/core/cli.d.mts.map +1 -1
  25. package/dist/_vendor/core/cli.mjs +458 -133
  26. package/dist/_vendor/core/cli.mjs.map +1 -1
  27. package/dist/_vendor/core/devtools-auth.mjs +60 -0
  28. package/dist/_vendor/core/devtools-auth.mjs.map +1 -0
  29. package/dist/_vendor/core/index.d.mts +5 -3
  30. package/dist/_vendor/core/index.mjs +22 -2
  31. package/dist/_vendor/core/index.mjs.map +1 -1
  32. package/dist/_vendor/core/runtime/components.d.mts +111 -0
  33. package/dist/_vendor/core/runtime/components.d.mts.map +1 -0
  34. package/dist/_vendor/core/runtime/components.mjs +186 -0
  35. package/dist/_vendor/core/runtime/components.mjs.map +1 -0
  36. package/dist/_vendor/core/runtime/devtools.d.mts +4 -4
  37. package/dist/_vendor/core/runtime/devtools.d.mts.map +1 -1
  38. package/dist/_vendor/core/runtime/devtools.mjs +178 -60
  39. package/dist/_vendor/core/runtime/devtools.mjs.map +1 -1
  40. package/dist/_vendor/core/runtime/functions.d.mts +398 -16
  41. package/dist/_vendor/core/runtime/functions.d.mts.map +1 -1
  42. package/dist/_vendor/core/runtime/functions.mjs +74 -3
  43. package/dist/_vendor/core/runtime/functions.mjs.map +1 -1
  44. package/dist/_vendor/core/runtime/id.d.mts.map +1 -1
  45. package/dist/_vendor/core/runtime/id.mjs.map +1 -1
  46. package/dist/_vendor/core/runtime/internal/engines/devtoolsEngine.mjs +83 -0
  47. package/dist/_vendor/core/runtime/internal/engines/devtoolsEngine.mjs.map +1 -0
  48. package/dist/_vendor/core/runtime/internal/engines/executionEngine.mjs +720 -0
  49. package/dist/_vendor/core/runtime/internal/engines/executionEngine.mjs.map +1 -0
  50. package/dist/_vendor/core/runtime/internal/engines/reactivityEngine.mjs +234 -0
  51. package/dist/_vendor/core/runtime/internal/engines/reactivityEngine.mjs.map +1 -0
  52. package/dist/_vendor/core/runtime/internal/engines/schedulerEngine.mjs +255 -0
  53. package/dist/_vendor/core/runtime/internal/engines/schedulerEngine.mjs.map +1 -0
  54. package/dist/_vendor/core/runtime/internal/engines/schemaEngine.mjs +200 -0
  55. package/dist/_vendor/core/runtime/internal/engines/schemaEngine.mjs.map +1 -0
  56. package/dist/_vendor/core/runtime/internal/engines/shared.mjs +252 -0
  57. package/dist/_vendor/core/runtime/internal/engines/shared.mjs.map +1 -0
  58. package/dist/_vendor/core/runtime/internal/engines/storageEngine.mjs +145 -0
  59. package/dist/_vendor/core/runtime/internal/engines/storageEngine.mjs.map +1 -0
  60. package/dist/_vendor/core/runtime/internal/runtimeKernel.mjs +221 -0
  61. package/dist/_vendor/core/runtime/internal/runtimeKernel.mjs.map +1 -0
  62. package/dist/_vendor/core/runtime/internal/runtimeStatus.mjs +32 -0
  63. package/dist/_vendor/core/runtime/internal/runtimeStatus.mjs.map +1 -0
  64. package/dist/_vendor/core/runtime/internal/systemMeta.mjs +61 -0
  65. package/dist/_vendor/core/runtime/internal/systemMeta.mjs.map +1 -0
  66. package/dist/_vendor/core/runtime/internal/transactionCoordinator.mjs +41 -0
  67. package/dist/_vendor/core/runtime/internal/transactionCoordinator.mjs.map +1 -0
  68. package/dist/_vendor/core/runtime/runtime.d.mts +1187 -202
  69. package/dist/_vendor/core/runtime/runtime.d.mts.map +1 -1
  70. package/dist/_vendor/core/runtime/runtime.mjs +73 -1365
  71. package/dist/_vendor/core/runtime/runtime.mjs.map +1 -1
  72. package/dist/_vendor/core/transport.d.mts +113 -0
  73. package/dist/_vendor/core/transport.d.mts.map +1 -0
  74. package/dist/_vendor/core/transport.mjs +428 -0
  75. package/dist/_vendor/core/transport.mjs.map +1 -0
  76. package/dist/_vendor/devtools-protocol/index.d.ts +187 -4
  77. package/dist/_vendor/devtools-protocol/index.d.ts.map +1 -1
  78. package/dist/_vendor/devtools-protocol/index.js +25 -9
  79. package/dist/_vendor/devtools-protocol/index.js.map +1 -1
  80. package/dist/_vendor/next/config.d.ts +3 -4
  81. package/dist/_vendor/next/config.d.ts.map +1 -1
  82. package/dist/_vendor/next/config.js +37 -19
  83. package/dist/_vendor/next/config.js.map +1 -1
  84. package/dist/_vendor/next/index.d.ts +109 -29
  85. package/dist/_vendor/next/index.d.ts.map +1 -1
  86. package/dist/_vendor/next/index.js +104 -26
  87. package/dist/_vendor/next/index.js.map +1 -1
  88. package/dist/_vendor/platform-expo/index.d.ts +156 -37
  89. package/dist/_vendor/platform-expo/index.d.ts.map +1 -1
  90. package/dist/_vendor/platform-expo/index.js +80 -12
  91. package/dist/_vendor/platform-expo/index.js.map +1 -1
  92. package/dist/_vendor/platform-expo/react.d.ts.map +1 -1
  93. package/dist/_vendor/platform-expo/react.js +11 -10
  94. package/dist/_vendor/platform-expo/react.js.map +1 -1
  95. package/dist/_vendor/platform-expo/web-sqljs-wasm.js +16 -0
  96. package/dist/_vendor/platform-expo/web-sqljs-wasm.js.map +1 -0
  97. package/dist/_vendor/platform-node/index.d.mts +192 -24
  98. package/dist/_vendor/platform-node/index.d.mts.map +1 -1
  99. package/dist/_vendor/platform-node/index.mjs +236 -97
  100. package/dist/_vendor/platform-node/index.mjs.map +1 -1
  101. package/dist/_vendor/platform-node/ipc-react.d.mts.map +1 -1
  102. package/dist/_vendor/platform-node/ipc-react.mjs +15 -2
  103. package/dist/_vendor/platform-node/ipc-react.mjs.map +1 -1
  104. package/dist/_vendor/platform-node/ipc.d.mts +11 -35
  105. package/dist/_vendor/platform-node/ipc.d.mts.map +1 -1
  106. package/dist/_vendor/platform-node/ipc.mjs +3 -273
  107. package/dist/_vendor/platform-node/ipc.mjs.map +1 -1
  108. package/dist/_vendor/platform-web/external-change.d.ts +43 -1
  109. package/dist/_vendor/platform-web/external-change.d.ts.map +1 -1
  110. package/dist/_vendor/platform-web/external-change.js +32 -1
  111. package/dist/_vendor/platform-web/external-change.js.map +1 -1
  112. package/dist/_vendor/platform-web/index.d.ts +323 -51
  113. package/dist/_vendor/platform-web/index.d.ts.map +1 -1
  114. package/dist/_vendor/platform-web/index.js +233 -30
  115. package/dist/_vendor/platform-web/index.js.map +1 -1
  116. package/dist/_vendor/platform-web/indexeddb.d.ts +12 -0
  117. package/dist/_vendor/platform-web/indexeddb.d.ts.map +1 -1
  118. package/dist/_vendor/platform-web/indexeddb.js +10 -0
  119. package/dist/_vendor/platform-web/indexeddb.js.map +1 -1
  120. package/dist/_vendor/platform-web/opfs.d.ts +13 -0
  121. package/dist/_vendor/platform-web/opfs.d.ts.map +1 -1
  122. package/dist/_vendor/platform-web/opfs.js +12 -0
  123. package/dist/_vendor/platform-web/opfs.js.map +1 -1
  124. package/dist/_vendor/platform-web/persistence.d.ts +54 -0
  125. package/dist/_vendor/platform-web/persistence.d.ts.map +1 -1
  126. package/dist/_vendor/platform-web/persistence.js +15 -0
  127. package/dist/_vendor/platform-web/persistence.js.map +1 -1
  128. package/dist/_vendor/platform-web/react.d.ts +1 -2
  129. package/dist/_vendor/platform-web/react.d.ts.map +1 -1
  130. package/dist/_vendor/platform-web/react.js +27 -13
  131. package/dist/_vendor/platform-web/react.js.map +1 -1
  132. package/dist/_vendor/platform-web/sqljs.js +10 -1
  133. package/dist/_vendor/platform-web/sqljs.js.map +1 -1
  134. package/dist/_vendor/platform-web/web-sqljs-wasm.js +8 -0
  135. package/dist/_vendor/platform-web/web-sqljs-wasm.js.map +1 -0
  136. package/dist/_vendor/platform-web/worker.d.ts +71 -44
  137. package/dist/_vendor/platform-web/worker.d.ts.map +1 -1
  138. package/dist/_vendor/platform-web/worker.js +40 -271
  139. package/dist/_vendor/platform-web/worker.js.map +1 -1
  140. package/dist/_vendor/react/index.d.ts +222 -23
  141. package/dist/_vendor/react/index.d.ts.map +1 -1
  142. package/dist/_vendor/react/index.js +476 -63
  143. package/dist/_vendor/react/index.js.map +1 -1
  144. package/dist/_vendor/schema/definition.d.ts +151 -37
  145. package/dist/_vendor/schema/definition.d.ts.map +1 -1
  146. package/dist/_vendor/schema/definition.js +102 -20
  147. package/dist/_vendor/schema/definition.js.map +1 -1
  148. package/dist/_vendor/schema/index.d.ts +4 -4
  149. package/dist/_vendor/schema/index.js +2 -2
  150. package/dist/_vendor/schema/planner.d.ts +19 -2
  151. package/dist/_vendor/schema/planner.d.ts.map +1 -1
  152. package/dist/_vendor/schema/planner.js +79 -3
  153. package/dist/_vendor/schema/planner.js.map +1 -1
  154. package/dist/_vendor/schema/validators.d.ts +279 -83
  155. package/dist/_vendor/schema/validators.d.ts.map +1 -1
  156. package/dist/_vendor/schema/validators.js +330 -38
  157. package/dist/_vendor/schema/validators.js.map +1 -1
  158. package/dist/_vendor/svelte/index.d.ts +245 -19
  159. package/dist/_vendor/svelte/index.d.ts.map +1 -1
  160. package/dist/_vendor/svelte/index.js +443 -20
  161. package/dist/_vendor/svelte/index.js.map +1 -1
  162. package/dist/browser.d.ts.map +1 -1
  163. package/dist/cli.js +3 -1
  164. package/dist/cli.js.map +1 -1
  165. package/dist/components.d.ts +2 -0
  166. package/dist/components.js +2 -0
  167. package/dist/index.d.ts +3 -2
  168. package/dist/index.js +2 -1
  169. package/package.json +29 -21
@@ -1,10 +1,11 @@
1
+ import { parseCanonicalComponentFunctionName, parseComponentScopedIdentifier, quoteIdentifier, safeReadRecurringSchedule } from "./internal/engines/shared.mjs";
1
2
  import { createFunctionReference } from "./runtime.mjs";
2
3
  import { describeValidator } from "../../schema/index.js";
3
4
  //#region src/runtime/devtools.ts
4
5
  function createDevtoolsCommandHandler(deps) {
5
- const { driver, runtime, sql } = deps;
6
+ const { driver, admin, sql } = deps;
6
7
  return async (payload) => {
7
- await runtime.prepareForDirectAccess();
8
+ await admin.prepareForDirectAccess();
8
9
  switch (payload.kind) {
9
10
  case "fn.run": {
10
11
  const start = performance.now();
@@ -12,13 +13,13 @@ function createDevtoolsCommandHandler(deps) {
12
13
  let result;
13
14
  switch (payload.functionType) {
14
15
  case "query":
15
- result = await runtime.runQuery(createFunctionReference("query", payload.functionName), payload.args, { origin: "dashboard" });
16
+ result = await admin.runQuery(createFunctionReference("query", payload.functionName), payload.args, { origin: "dashboard" });
16
17
  break;
17
18
  case "mutation":
18
- result = await runtime.runMutation(createFunctionReference("mutation", payload.functionName), payload.args, { origin: "dashboard" });
19
+ result = await admin.runMutation(createFunctionReference("mutation", payload.functionName), payload.args, { origin: "dashboard" });
19
20
  break;
20
21
  case "action":
21
- result = await runtime.runAction(createFunctionReference("action", payload.functionName), payload.args, { origin: "dashboard" });
22
+ result = await admin.runAction(createFunctionReference("action", payload.functionName), payload.args, { origin: "dashboard" });
22
23
  break;
23
24
  }
24
25
  return {
@@ -35,10 +36,12 @@ function createDevtoolsCommandHandler(deps) {
35
36
  }
36
37
  }
37
38
  case "data.insert": try {
39
+ const id = await runDevtoolsMutation(admin, async (ctx) => ctx.db.insert(payload.table, payload.document), { origin: "dashboard" });
40
+ notifyDataMutationScopes(admin, payload.table);
38
41
  return {
39
42
  kind: "data.mutate.result",
40
43
  success: true,
41
- id: await runDevtoolsMutation(runtime, async (ctx) => ctx.db.insert(payload.table, payload.document), { origin: "dashboard" })
44
+ id
42
45
  };
43
46
  } catch (error) {
44
47
  return {
@@ -48,10 +51,11 @@ function createDevtoolsCommandHandler(deps) {
48
51
  };
49
52
  }
50
53
  case "data.patch": try {
51
- await runDevtoolsMutation(runtime, async (ctx) => {
54
+ await runDevtoolsMutation(admin, async (ctx) => {
52
55
  await ctx.db.patch(payload.table, payload.id, payload.fields);
53
56
  return null;
54
57
  }, { origin: "dashboard" });
58
+ notifyDataMutationScopes(admin, payload.table);
55
59
  return {
56
60
  kind: "data.mutate.result",
57
61
  success: true,
@@ -65,10 +69,11 @@ function createDevtoolsCommandHandler(deps) {
65
69
  };
66
70
  }
67
71
  case "data.delete": try {
68
- await runDevtoolsMutation(runtime, async (ctx) => {
72
+ await runDevtoolsMutation(admin, async (ctx) => {
69
73
  await ctx.db.delete(payload.table, payload.id);
70
74
  return null;
71
75
  }, { origin: "dashboard" });
76
+ notifyDataMutationScopes(admin, payload.table);
72
77
  return {
73
78
  kind: "data.mutate.result",
74
79
  success: true
@@ -80,9 +85,54 @@ function createDevtoolsCommandHandler(deps) {
80
85
  error: error instanceof Error ? error.message : String(error)
81
86
  };
82
87
  }
88
+ case "data.export": try {
89
+ const requestedTables = payload.tables && payload.tables.length > 0 ? payload.tables : deps.schema.tableNames();
90
+ return {
91
+ kind: "data.export.result",
92
+ tables: await Promise.all(requestedTables.map(async (name) => {
93
+ const result = await queryTable(driver, name);
94
+ return {
95
+ name,
96
+ rows: result.rows,
97
+ totalCount: result.totalCount
98
+ };
99
+ }))
100
+ };
101
+ } catch (error) {
102
+ return {
103
+ kind: "data.export.result",
104
+ tables: [],
105
+ error: error instanceof Error ? error.message : String(error)
106
+ };
107
+ }
108
+ case "data.referenceOptions": {
109
+ const limit = Math.min(Math.max(payload.limit ?? 100, 1), 200);
110
+ const offset = Math.max(payload.offset ?? 0, 0);
111
+ try {
112
+ const result = await queryReferenceOptions(driver, payload.table, payload.search, limit, offset);
113
+ return {
114
+ kind: "data.referenceOptions.result",
115
+ table: payload.table,
116
+ rows: result.rows,
117
+ totalCount: result.totalCount,
118
+ offset,
119
+ hasMore: offset + result.rows.length < result.totalCount
120
+ };
121
+ } catch (error) {
122
+ return {
123
+ kind: "data.referenceOptions.result",
124
+ table: payload.table,
125
+ rows: [],
126
+ totalCount: 0,
127
+ offset,
128
+ hasMore: false,
129
+ error: error instanceof Error ? error.message : String(error)
130
+ };
131
+ }
132
+ }
83
133
  case "sql.read": try {
84
134
  const sqlSupport = requireDevtoolsSqlSupport(sql);
85
- const databasePath = runtime.getDriverDatabasePath();
135
+ const databasePath = admin.getDriverDatabasePath();
86
136
  if (!databasePath) throw new Error("SQL Read requires a file-backed database path.");
87
137
  const { columns, rows } = sqlSupport.runReadonlyQuery(databasePath, payload.query);
88
138
  return {
@@ -102,8 +152,8 @@ function createDevtoolsCommandHandler(deps) {
102
152
  const analysis = requireDevtoolsSqlSupport(sql).analyzeSqlStatement(payload.query);
103
153
  if (analysis.mode === "read") throw new Error("Use SQL Read or SQL Live for read-only statements.");
104
154
  const result = await driver.run(payload.query);
105
- runtime.notifyDevtoolsScopes(analysis.observedScopes);
106
- await runtime.forceRefreshDevtools("SQL write executed from devtools dashboard.", { origin: "dashboard" });
155
+ admin.notifyDevtoolsScopes(analysis.observedScopes);
156
+ await admin.forceRefreshDevtools("SQL write executed from devtools dashboard.", analysis.observedScopes.flatMap((scope) => scope === "all" ? [] : [scope]), { origin: "dashboard" });
107
157
  return {
108
158
  kind: "sql.write.result",
109
159
  rowsAffected: result.changes,
@@ -121,7 +171,7 @@ function createDevtoolsCommandHandler(deps) {
121
171
  return {
122
172
  kind: "scheduler.cancel.result",
123
173
  success: true,
124
- cancelled: await runtime.cancelScheduledJob(payload.jobId)
174
+ cancelled: await admin.cancelScheduledJob(payload.jobId)
125
175
  };
126
176
  } catch (error) {
127
177
  return {
@@ -132,11 +182,11 @@ function createDevtoolsCommandHandler(deps) {
132
182
  };
133
183
  }
134
184
  case "scheduler.update": try {
135
- const updated = await runtime.updateScheduledJob({
185
+ const updated = await admin.updateScheduledJob({
136
186
  id: payload.jobId,
137
- schedule: payload.schedule,
138
187
  args: payload.args,
139
- misfirePolicy: payload.misfirePolicy,
188
+ ...payload.schedule ? { schedule: payload.schedule } : {},
189
+ ...payload.misfirePolicy ? { misfirePolicy: payload.misfirePolicy } : {},
140
190
  ...payload.runAt !== void 0 ? { runAt: payload.runAt } : {}
141
191
  });
142
192
  const updatedJob = (updated ? await listSchedulerJobs(driver) : []).find((job) => job.id === payload.jobId);
@@ -162,14 +212,14 @@ function createDevtoolsCommandHandler(deps) {
162
212
  };
163
213
  }
164
214
  function createDevtoolsSubscriptionHost(deps) {
165
- const { driver, schema, functions, runtime } = deps;
215
+ const { driver, schema, functions, admin } = deps;
166
216
  const subscriptions = /* @__PURE__ */ new Map();
167
217
  const emit = async (payload, listener) => {
168
218
  listener(await resolveSubscriptionPayload(payload, {
169
219
  driver,
170
220
  schema,
171
221
  functions,
172
- runtime,
222
+ admin,
173
223
  ...deps.sql ? { sql: deps.sql } : {}
174
224
  }));
175
225
  };
@@ -190,7 +240,7 @@ function createDevtoolsSubscriptionHost(deps) {
190
240
  });
191
241
  return;
192
242
  }
193
- const watch = runtime.createClient().watchQuery(createFunctionReference("query", payload.functionName), payload.args);
243
+ const watch = admin.createClient().watchQuery(createFunctionReference("query", payload.functionName), payload.args);
194
244
  const emitWatchResult = () => {
195
245
  const error = watch.localQueryError();
196
246
  listener({
@@ -211,10 +261,10 @@ function createDevtoolsSubscriptionHost(deps) {
211
261
  emitWatchResult();
212
262
  return;
213
263
  }
214
- const unsubscribeRuntime = runtime.subscribeToDevtoolsInvalidations((scopes) => {
264
+ const unsubscribeRuntime = admin.subscribeToDevtoolsInvalidations((scopes) => {
215
265
  handleInvalidation(scopes);
216
266
  });
217
- const unsubscribeEvents = runtime.subscribeToDevtoolsEvents((event) => {
267
+ const unsubscribeEvents = admin.subscribeToDevtoolsEvents((event) => {
218
268
  if (event.type === "runtime.disconnected") emit(payload, listener);
219
269
  });
220
270
  subscriptions.set(subscriptionId, {
@@ -243,22 +293,22 @@ function createDevtoolsSubscriptionHost(deps) {
243
293
  };
244
294
  }
245
295
  async function resolveSubscriptionPayload(payload, deps) {
246
- const { driver, schema, functions, runtime } = deps;
247
- await runtime.prepareForDirectAccess();
296
+ const { driver, schema, functions, admin } = deps;
297
+ await admin.prepareForDirectAccess();
248
298
  switch (payload.kind) {
249
299
  case "runtime.summary": return {
250
300
  kind: "runtime.summary.result",
251
- summary: runtime.getRuntimeSummary()
301
+ summary: admin.getRuntimeSummary()
252
302
  };
253
303
  case "runtime.activeQueries": return {
254
304
  kind: "runtime.activeQueries.result",
255
- activeQueries: runtime.getActiveQueryInfos()
305
+ activeQueries: admin.getActiveQueryInfos()
256
306
  };
257
307
  case "fn.watch": throw new Error("Function watches are pushed incrementally and have no snapshot payload.");
258
308
  case "schema.tables": {
259
309
  const tables = await getSchemaTables(driver, schema);
260
310
  console.debug("[devtools] schema.tables", {
261
- runtimeId: runtime.getRuntimeId(),
311
+ runtimeId: admin.getRuntimeId(),
262
312
  tables: tables.map((table) => ({
263
313
  name: table.name,
264
314
  documentCount: table.documentCount
@@ -272,7 +322,7 @@ async function resolveSubscriptionPayload(payload, deps) {
272
322
  case "data.table": {
273
323
  const result = await queryTable(driver, payload.table, payload.filters, payload.limit);
274
324
  console.debug("[devtools] data.table", {
275
- runtimeId: runtime.getRuntimeId(),
325
+ runtimeId: admin.getRuntimeId(),
276
326
  table: payload.table,
277
327
  filters: payload.filters ?? [],
278
328
  limit: payload.limit,
@@ -297,7 +347,7 @@ async function resolveSubscriptionPayload(payload, deps) {
297
347
  };
298
348
  case "sql.watch": {
299
349
  const sqlSupport = requireDevtoolsSqlSupport(deps.sql);
300
- const databasePath = runtime.getDriverDatabasePath();
350
+ const databasePath = admin.getDriverDatabasePath();
301
351
  if (!databasePath) throw new Error("SQL Live requires a file-backed database path.");
302
352
  const { columns, rows, observedTables } = sqlSupport.runReadonlyQuery(databasePath, payload.query);
303
353
  return {
@@ -310,12 +360,16 @@ async function resolveSubscriptionPayload(payload, deps) {
310
360
  }
311
361
  }
312
362
  async function queryTable(driver, table, filters, limit) {
313
- let sql = `SELECT _id, _creationTime, _json FROM "${table}"`;
363
+ let sql = `SELECT _id, _creationTime, _json FROM ${quoteIdentifier(table)}`;
314
364
  const params = [];
315
- if (filters && filters.length > 0) sql += ` WHERE ${filters.map((filter) => {
316
- params.push(normalizeFilterValue(filter));
317
- return `json_extract(_json, '$.${filter.field}') ${filterOperatorToSql(filter.operator)} ?`;
318
- }).join(" AND ")}`;
365
+ const whereClauses = [];
366
+ if (filters && filters.length > 0) {
367
+ for (const filter of filters) {
368
+ whereClauses.push(filterToSql(filter));
369
+ params.push(normalizeFilterValue(filter));
370
+ }
371
+ sql += ` WHERE ${whereClauses.join(" AND ")}`;
372
+ }
319
373
  sql += " ORDER BY _creationTime DESC";
320
374
  if (limit) sql += ` LIMIT ${limit}`;
321
375
  return {
@@ -324,7 +378,30 @@ async function queryTable(driver, table, filters, limit) {
324
378
  _creationTime: row._creationTime,
325
379
  ...JSON.parse(row._json)
326
380
  })),
327
- totalCount: (await driver.get(`SELECT COUNT(*) as count FROM "${table}"`))?.count ?? 0
381
+ totalCount: (await driver.get(`SELECT COUNT(*) as count FROM ${quoteIdentifier(table)}${whereClauses.length > 0 ? ` WHERE ${whereClauses.join(" AND ")}` : ""}`, params))?.count ?? 0
382
+ };
383
+ }
384
+ async function queryReferenceOptions(driver, table, search, limit, offset) {
385
+ let sql = `SELECT _id, _creationTime, _json FROM ${quoteIdentifier(table)}`;
386
+ const params = [];
387
+ const trimmedSearch = search?.trim();
388
+ const whereClause = trimmedSearch ? " WHERE _id LIKE ? OR _json LIKE ?" : "";
389
+ if (trimmedSearch) {
390
+ const like = `%${trimmedSearch}%`;
391
+ params.push(like, like);
392
+ }
393
+ sql += `${whereClause} ORDER BY _creationTime DESC LIMIT ? OFFSET ?`;
394
+ return {
395
+ rows: (await driver.all(sql, [
396
+ ...params,
397
+ limit,
398
+ offset
399
+ ])).map((row) => ({
400
+ _id: row._id,
401
+ _creationTime: row._creationTime,
402
+ ...JSON.parse(row._json)
403
+ })),
404
+ totalCount: (await driver.get(`SELECT COUNT(*) as count FROM ${quoteIdentifier(table)}${whereClause}`, params))?.count ?? 0
328
405
  };
329
406
  }
330
407
  async function getSchemaTables(driver, schema) {
@@ -332,12 +409,12 @@ async function getSchemaTables(driver, schema) {
332
409
  const table = schema.getTable(name);
333
410
  const validatorDesc = describeValidator(table.validator);
334
411
  const fields = validatorDesc.kind === "object" ? Object.entries(validatorDesc.shape).map(([fieldName, fieldDesc]) => {
335
- const desc = fieldDesc;
336
- const optional = desc.kind === "optional";
412
+ const field = fieldDesc;
337
413
  return {
338
414
  name: fieldName,
339
- type: optional ? desc.inner?.kind ?? "any" : desc.kind,
340
- optional
415
+ type: field.validator.kind,
416
+ optional: field.optional,
417
+ ...field.validator.kind === "id" && field.validator.tableName ? { referenceTable: field.validator.tableName } : {}
341
418
  };
342
419
  }) : [];
343
420
  fields.unshift({
@@ -349,14 +426,13 @@ async function getSchemaTables(driver, schema) {
349
426
  type: "number",
350
427
  optional: false
351
428
  });
352
- let documentCount = 0;
353
- try {
354
- documentCount = (await driver.get(`SELECT COUNT(*) as count FROM "${name}"`))?.count ?? 0;
355
- } catch {
356
- documentCount = 0;
357
- }
429
+ const documentCount = await driver.get(`SELECT COUNT(*) as count FROM "${name}"`).then((countRow) => countRow?.count ?? 0).catch(() => 0);
358
430
  return {
359
431
  name,
432
+ ...table.options.tableName ? { displayName: table.options.tableName } : {},
433
+ owner: table.options.componentPath ? "component" : "root",
434
+ ...table.options.componentPath ? { componentPath: table.options.componentPath } : {},
435
+ ...table.options.componentName ? { componentName: table.options.componentName } : {},
360
436
  fields,
361
437
  indexes: table.indexes.map((index) => ({
362
438
  name: index.name,
@@ -370,11 +446,15 @@ async function getSchemaTables(driver, schema) {
370
446
  async function listSchedulerJobs(driver) {
371
447
  try {
372
448
  return (await driver.all(`SELECT * FROM "_scheduled_functions" ORDER BY run_at DESC LIMIT 200`)).map((row) => {
373
- const schedule = safeReadSchedule(row.schedule_json);
449
+ const schedule = safeReadRecurringSchedule(row.schedule_json);
374
450
  const scheduleLabel = schedule ? formatScheduleLabel(schedule) : void 0;
451
+ const functionComponent = parseCanonicalComponentFunctionName(row.function_name);
452
+ const idComponent = parseComponentScopedIdentifier(row.id);
375
453
  return {
376
454
  id: row.id,
377
455
  functionName: row.function_name,
456
+ owner: functionComponent || idComponent ? "component" : "root",
457
+ ...functionComponent ? { componentPath: functionComponent.componentPath } : idComponent ? { componentPath: idComponent.componentPath } : {},
378
458
  args: JSON.parse(row.args_json),
379
459
  scheduledAt: row.created_at,
380
460
  runAt: row.run_at,
@@ -398,10 +478,23 @@ async function listSchedulerJobs(driver) {
398
478
  }
399
479
  function listFunctions(functions) {
400
480
  return Object.entries(functions).filter((entry) => entry[1] !== void 0).map(([name, fn]) => {
481
+ const componentFunction = parseCanonicalComponentFunctionName(name);
401
482
  const descriptor = {
402
483
  name,
403
484
  type: fn.kind,
404
- file: inferFileFromFunctionName(name)
485
+ owner: componentFunction ? "component" : "root",
486
+ namespace: inferFunctionNamespace(name),
487
+ metadataAvailable: componentFunction !== null || name.includes(":"),
488
+ ...componentFunction ? {
489
+ file: `components/${componentFunction.componentPath}`,
490
+ modulePath: componentFunction.componentPath,
491
+ componentPath: componentFunction.componentPath,
492
+ visibility: componentFunction.visibility,
493
+ localName: componentFunction.localName
494
+ } : inferFileFromFunctionName(name) ? {
495
+ file: inferFileFromFunctionName(name),
496
+ modulePath: inferFunctionNamespace(name)
497
+ } : {}
405
498
  };
406
499
  const argsDesc = describeValidator(fn.argsValidator);
407
500
  if (argsDesc.kind === "object") descriptor.args = argsDesc.shape;
@@ -409,17 +502,45 @@ function listFunctions(functions) {
409
502
  });
410
503
  }
411
504
  function inferFileFromFunctionName(name) {
505
+ const componentFunction = parseCanonicalComponentFunctionName(name);
506
+ if (componentFunction) return `components/${componentFunction.componentPath}`;
412
507
  const parts = name.split(":");
413
508
  if (parts.length > 1) return `${parts[0]}.ts`;
414
- return "unknown";
509
+ return "";
510
+ }
511
+ function inferFunctionNamespace(name) {
512
+ const componentFunction = parseCanonicalComponentFunctionName(name);
513
+ if (componentFunction) return componentFunction.componentPath;
514
+ if (name.includes(":")) return name.split(":")[0] ?? "root";
515
+ if (name.includes("/")) return name.split("/")[0] ?? "root";
516
+ return "root";
415
517
  }
416
518
  function normalizeFilterValue(filter) {
519
+ const value = coerceFilterValue(filter.value);
417
520
  switch (filter.operator) {
418
- case "contains": return `%${String(filter.value)}%`;
419
- case "startsWith": return `${String(filter.value)}%`;
420
- default: return filter.value;
521
+ case "contains": return `%${String(value)}%`;
522
+ case "startsWith": return `${String(value)}%`;
523
+ default: return value;
421
524
  }
422
525
  }
526
+ function filterToSql(filter) {
527
+ const operator = filterOperatorToSql(filter.operator);
528
+ if (filter.field === "_id") return `_id ${operator} ?`;
529
+ if (filter.field === "_creationTime") return `_creationTime ${operator} ?`;
530
+ return `json_extract(_json, ${JSON.stringify(`$.${filter.field}`)}) ${operator} ?`;
531
+ }
532
+ function coerceFilterValue(value) {
533
+ if (typeof value !== "string") return value;
534
+ const trimmed = value.trim();
535
+ if (trimmed === "true") return true;
536
+ if (trimmed === "false") return false;
537
+ if (trimmed === "null") return null;
538
+ if (/^-?\d+(?:\.\d+)?$/.test(trimmed)) {
539
+ const numberValue = Number(trimmed);
540
+ if (Number.isFinite(numberValue)) return numberValue;
541
+ }
542
+ return value;
543
+ }
423
544
  function filterOperatorToSql(operator) {
424
545
  switch (operator) {
425
546
  case "eq": return "=";
@@ -443,14 +564,6 @@ function mapJobStatus(status) {
443
564
  default: return "pending";
444
565
  }
445
566
  }
446
- function safeReadSchedule(scheduleJson) {
447
- if (!scheduleJson) return;
448
- try {
449
- return JSON.parse(scheduleJson);
450
- } catch {
451
- return;
452
- }
453
- }
454
567
  function formatScheduleLabel(schedule) {
455
568
  switch (schedule.type) {
456
569
  case "interval": {
@@ -462,6 +575,7 @@ function formatScheduleLabel(schedule) {
462
575
  }
463
576
  case "daily": return `Daily ${padNumber(schedule.hour)}:${padNumber(schedule.minute)}${schedule.timezone ? ` ${schedule.timezone}` : ""}`;
464
577
  case "weekly": return `Weekly ${capitalize(schedule.dayOfWeek)} ${padNumber(schedule.hour)}:${padNumber(schedule.minute)}${schedule.timezone ? ` ${schedule.timezone}` : ""}`;
578
+ default: return "Recurring";
465
579
  }
466
580
  }
467
581
  function readMisfirePolicy(type, windowMs) {
@@ -478,8 +592,11 @@ function padNumber(value) {
478
592
  function capitalize(value) {
479
593
  return value.slice(0, 1).toUpperCase() + value.slice(1);
480
594
  }
481
- async function runDevtoolsMutation(runtime, callback, meta) {
482
- return runtime.runDevtoolsMutation(callback, meta);
595
+ async function runDevtoolsMutation(admin, callback, meta) {
596
+ return admin.runDevtoolsMutation(callback, meta);
597
+ }
598
+ function notifyDataMutationScopes(admin, tableName) {
599
+ admin.notifyDevtoolsScopes(["schema.tables", `table:${tableName}`]);
483
600
  }
484
601
  function scopesForSubscription(payload, sql) {
485
602
  switch (payload.kind) {
@@ -498,6 +615,7 @@ function scopesForSubscription(payload, sql) {
498
615
  } catch {
499
616
  return new Set(["all"]);
500
617
  }
618
+ default: return new Set(["all"]);
501
619
  }
502
620
  }
503
621
  function intersects(a, b) {
@@ -506,7 +624,7 @@ function intersects(a, b) {
506
624
  return false;
507
625
  }
508
626
  function requireDevtoolsSqlSupport(sql) {
509
- if (!sql) throw new Error("SQL devtools are only available in Node-hosted runtimes.");
627
+ if (!sql) throw new Error("SQL Console is not available for this runtime.");
510
628
  return sql;
511
629
  }
512
630
  //#endregion