@typicalday/firegraph 0.8.0 → 0.9.0

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 (65) hide show
  1. package/dist/backend.cjs +222 -0
  2. package/dist/backend.cjs.map +1 -0
  3. package/dist/backend.d.cts +121 -0
  4. package/dist/backend.d.ts +121 -0
  5. package/dist/backend.js +136 -0
  6. package/dist/backend.js.map +1 -0
  7. package/dist/{chunk-6OQW5OKO.js → chunk-5753Y42M.js} +12 -4
  8. package/dist/chunk-5753Y42M.js.map +1 -0
  9. package/dist/{chunk-YUXOALMR.js → chunk-EVUM6ORB.js} +14 -92
  10. package/dist/chunk-EVUM6ORB.js.map +1 -0
  11. package/dist/chunk-GLOVWKQH.js +94 -0
  12. package/dist/chunk-GLOVWKQH.js.map +1 -0
  13. package/dist/{chunk-KFA7G37W.js → chunk-SU4FNLC3.js} +32 -30
  14. package/dist/chunk-SU4FNLC3.js.map +1 -0
  15. package/dist/{chunk-WOAJRVHD.js → chunk-SZ6W4VAS.js} +5 -3
  16. package/dist/{chunk-WOAJRVHD.js.map → chunk-SZ6W4VAS.js.map} +1 -1
  17. package/dist/chunk-TYYPRVIE.js +57 -0
  18. package/dist/chunk-TYYPRVIE.js.map +1 -0
  19. package/dist/codegen/index.d.cts +1 -1
  20. package/dist/codegen/index.d.ts +1 -1
  21. package/dist/d1.cjs +11 -6
  22. package/dist/d1.cjs.map +1 -1
  23. package/dist/d1.d.cts +1 -1
  24. package/dist/d1.d.ts +1 -1
  25. package/dist/d1.js +3 -2
  26. package/dist/d1.js.map +1 -1
  27. package/dist/do-sqlite.cjs +11 -6
  28. package/dist/do-sqlite.cjs.map +1 -1
  29. package/dist/do-sqlite.d.cts +1 -1
  30. package/dist/do-sqlite.d.ts +1 -1
  31. package/dist/do-sqlite.js +3 -2
  32. package/dist/do-sqlite.js.map +1 -1
  33. package/dist/editor/client/assets/index-Bq2bfzeY.js +411 -0
  34. package/dist/editor/client/index.html +1 -1
  35. package/dist/editor/server/index.mjs +6432 -6333
  36. package/dist/index.cjs +110 -44
  37. package/dist/index.cjs.map +1 -1
  38. package/dist/index.d.cts +5 -133
  39. package/dist/index.d.ts +5 -133
  40. package/dist/index.js +36 -27
  41. package/dist/index.js.map +1 -1
  42. package/dist/query-client/index.cjs +30 -28
  43. package/dist/query-client/index.cjs.map +1 -1
  44. package/dist/query-client/index.d.cts +2 -2
  45. package/dist/query-client/index.d.ts +2 -2
  46. package/dist/query-client/index.js +1 -1
  47. package/dist/react.cjs +0 -1
  48. package/dist/react.cjs.map +1 -1
  49. package/dist/react.js +0 -1
  50. package/dist/react.js.map +1 -1
  51. package/dist/scope-path-BtajqNK5.d.ts +234 -0
  52. package/dist/scope-path-D2mNENJ-.d.cts +234 -0
  53. package/dist/{serialization-C6JNNOCS.js → serialization-ZZ7RSDRX.js} +2 -2
  54. package/dist/svelte.cjs +0 -2
  55. package/dist/svelte.cjs.map +1 -1
  56. package/dist/svelte.js +0 -2
  57. package/dist/svelte.js.map +1 -1
  58. package/dist/{types-BVtx9zLv.d.cts → types-DfWVTsMn.d.cts} +3 -2
  59. package/dist/{types-BVtx9zLv.d.ts → types-DfWVTsMn.d.ts} +3 -2
  60. package/package.json +12 -1
  61. package/dist/chunk-6OQW5OKO.js.map +0 -1
  62. package/dist/chunk-KFA7G37W.js.map +0 -1
  63. package/dist/chunk-YUXOALMR.js.map +0 -1
  64. package/dist/editor/client/assets/index-tyFcX6qG.js +0 -411
  65. /package/dist/{serialization-C6JNNOCS.js.map → serialization-ZZ7RSDRX.js.map} +0 -0
package/dist/index.cjs CHANGED
@@ -66,10 +66,18 @@ function serializeValue(value) {
66
66
  if (value === null || value === void 0) return value;
67
67
  if (typeof value !== "object") return value;
68
68
  if (isTimestamp(value)) {
69
- return { [SERIALIZATION_TAG]: "Timestamp", seconds: value.seconds, nanoseconds: value.nanoseconds };
69
+ return {
70
+ [SERIALIZATION_TAG]: "Timestamp",
71
+ seconds: value.seconds,
72
+ nanoseconds: value.nanoseconds
73
+ };
70
74
  }
71
75
  if (isGeoPoint(value)) {
72
- return { [SERIALIZATION_TAG]: "GeoPoint", latitude: value.latitude, longitude: value.longitude };
76
+ return {
77
+ [SERIALIZATION_TAG]: "GeoPoint",
78
+ latitude: value.latitude,
79
+ longitude: value.longitude
80
+ };
73
81
  }
74
82
  if (isDocumentReference(value)) {
75
83
  return { [SERIALIZATION_TAG]: "DocumentReference", path: value.path };
@@ -150,6 +158,7 @@ var init_serialization = __esm({
150
158
  var index_exports = {};
151
159
  __export(index_exports, {
152
160
  BOOTSTRAP_ENTRIES: () => BOOTSTRAP_ENTRIES,
161
+ CrossBackendTransactionError: () => CrossBackendTransactionError,
153
162
  DEFAULT_QUERY_LIMIT: () => DEFAULT_QUERY_LIMIT,
154
163
  DiscoveryError: () => DiscoveryError,
155
164
  DynamicRegistryError: () => DynamicRegistryError,
@@ -171,6 +180,7 @@ __export(index_exports, {
171
180
  TraversalError: () => TraversalError,
172
181
  ValidationError: () => ValidationError,
173
182
  analyzeQuerySafety: () => analyzeQuerySafety,
183
+ appendStorageScope: () => appendStorageScope,
174
184
  applyMigrationChain: () => applyMigrationChain,
175
185
  buildEdgeQueryPlan: () => buildEdgeQueryPlan,
176
186
  buildEdgeRecord: () => buildEdgeRecord,
@@ -198,6 +208,7 @@ __export(index_exports, {
198
208
  generateId: () => generateId,
199
209
  generateIndexConfig: () => generateIndexConfig,
200
210
  generateTypes: () => generateTypes,
211
+ isAncestorScopeUid: () => isAncestorScopeUid,
201
212
  isAncestorUid: () => isAncestorUid,
202
213
  isTaggedValue: () => isTaggedValue,
203
214
  jsonSchemaToFieldMeta: () => jsonSchemaToFieldMeta,
@@ -205,8 +216,10 @@ __export(index_exports, {
205
216
  matchScopeAny: () => matchScopeAny,
206
217
  migrateRecord: () => migrateRecord,
207
218
  migrateRecords: () => migrateRecords,
219
+ parseStorageScope: () => parseStorageScope,
208
220
  precompileSource: () => precompileSource,
209
221
  resolveAncestorCollection: () => resolveAncestorCollection,
222
+ resolveAncestorScope: () => resolveAncestorScope,
210
223
  resolveView: () => resolveView,
211
224
  serializeFirestoreTypes: () => serializeFirestoreTypes,
212
225
  validateMigrationChain: () => validateMigrationChain
@@ -331,10 +344,7 @@ var ValidationError = class extends FiregraphError {
331
344
  };
332
345
  var RegistryViolationError = class extends FiregraphError {
333
346
  constructor(aType, axbType, bType) {
334
- super(
335
- `Unregistered triple: (${aType}) -[${axbType}]-> (${bType})`,
336
- "REGISTRY_VIOLATION"
337
- );
347
+ super(`Unregistered triple: (${aType}) -[${axbType}]-> (${bType})`, "REGISTRY_VIOLATION");
338
348
  this.name = "RegistryViolationError";
339
349
  }
340
350
  };
@@ -377,6 +387,12 @@ var MigrationError = class extends FiregraphError {
377
387
  this.name = "MigrationError";
378
388
  }
379
389
  };
390
+ var CrossBackendTransactionError = class extends FiregraphError {
391
+ constructor(message) {
392
+ super(message, "CROSS_BACKEND_TRANSACTION");
393
+ this.name = "CrossBackendTransactionError";
394
+ }
395
+ };
380
396
 
381
397
  // src/json-schema.ts
382
398
  var import_ajv = __toESM(require("ajv"), 1);
@@ -398,9 +414,7 @@ function compileSchema(schema, label) {
398
414
  }
399
415
  function jsonSchemaToFieldMeta(schema) {
400
416
  if (!schema || schema.type !== "object" || !schema.properties) return [];
401
- const requiredSet = new Set(
402
- Array.isArray(schema.required) ? schema.required : []
403
- );
417
+ const requiredSet = new Set(Array.isArray(schema.required) ? schema.required : []);
404
418
  return Object.entries(schema.properties).map(
405
419
  ([name, prop]) => propertyToFieldMeta(name, prop, requiredSet.has(name))
406
420
  );
@@ -2035,14 +2049,10 @@ function loadEdgeEntity(dir, name) {
2035
2049
  }
2036
2050
  const topology = readJson(edgePath);
2037
2051
  if (!topology.from) {
2038
- throw new DiscoveryError(
2039
- `edge.json for "${name}" is missing required "from" field`
2040
- );
2052
+ throw new DiscoveryError(`edge.json for "${name}" is missing required "from" field`);
2041
2053
  }
2042
2054
  if (!topology.to) {
2043
- throw new DiscoveryError(
2044
- `edge.json for "${name}" is missing required "to" field`
2045
- );
2055
+ throw new DiscoveryError(`edge.json for "${name}" is missing required "to" field`);
2046
2056
  }
2047
2057
  const meta = readJsonIfExists((0, import_node_path.join)(dir, "meta.json"));
2048
2058
  const sampleData = readJsonIfExists((0, import_node_path.join)(dir, "sample.json"));
@@ -2719,6 +2729,26 @@ function generateIndexConfig(collection, entities, registryEntries) {
2719
2729
  // src/query-client/client.ts
2720
2730
  var import_node_http = __toESM(require("http"), 1);
2721
2731
 
2732
+ // src/query-client/config.ts
2733
+ var import_node_fs2 = require("fs");
2734
+ var import_node_path2 = require("path");
2735
+ var CONFIG_FILES = ["firegraph.config.ts", "firegraph.config.js", "firegraph.config.mjs"];
2736
+ var DEFAULT_PORT = 3884;
2737
+ function readEditorPort(cwd) {
2738
+ const dir = cwd ?? process.cwd();
2739
+ for (const name of CONFIG_FILES) {
2740
+ try {
2741
+ const content = (0, import_node_fs2.readFileSync)((0, import_node_path2.join)(dir, name), "utf8");
2742
+ const editorBlock = content.match(/editor\s*:\s*\{[^}]*\}/s)?.[0] ?? "";
2743
+ const portMatch = editorBlock.match(/port\s*:\s*(\d+)/);
2744
+ if (portMatch) return parseInt(portMatch[1], 10);
2745
+ } catch {
2746
+ continue;
2747
+ }
2748
+ }
2749
+ return DEFAULT_PORT;
2750
+ }
2751
+
2722
2752
  // src/query-client/shaping.ts
2723
2753
  function summarizeRecord(r) {
2724
2754
  if (!r) return null;
@@ -2745,26 +2775,6 @@ function summarizeEdge(r) {
2745
2775
  return out;
2746
2776
  }
2747
2777
 
2748
- // src/query-client/config.ts
2749
- var import_node_fs2 = require("fs");
2750
- var import_node_path2 = require("path");
2751
- var CONFIG_FILES = ["firegraph.config.ts", "firegraph.config.js", "firegraph.config.mjs"];
2752
- var DEFAULT_PORT = 3884;
2753
- function readEditorPort(cwd) {
2754
- const dir = cwd ?? process.cwd();
2755
- for (const name of CONFIG_FILES) {
2756
- try {
2757
- const content = (0, import_node_fs2.readFileSync)((0, import_node_path2.join)(dir, name), "utf8");
2758
- const editorBlock = content.match(/editor\s*:\s*\{[^}]*\}/s)?.[0] ?? "";
2759
- const portMatch = editorBlock.match(/port\s*:\s*(\d+)/);
2760
- if (portMatch) return parseInt(portMatch[1], 10);
2761
- } catch {
2762
- continue;
2763
- }
2764
- }
2765
- return DEFAULT_PORT;
2766
- }
2767
-
2768
2778
  // src/query-client/client.ts
2769
2779
  var QueryClientError = class extends Error {
2770
2780
  constructor(message, code) {
@@ -2963,14 +2973,16 @@ var QueryClient = class {
2963
2973
  }
2964
2974
  const data = await this.mutate("traverse", input);
2965
2975
  return {
2966
- hops: (data.hops ?? []).map((h) => ({
2967
- relation: h.axbType,
2968
- direction: h.direction,
2969
- depth: h.depth,
2970
- edgeCount: (h.edges ?? []).length,
2971
- edges: (h.edges ?? []).map(summarizeEdge).filter(Boolean),
2972
- truncated: h.truncated ?? false
2973
- })),
2976
+ hops: (data.hops ?? []).map(
2977
+ (h) => ({
2978
+ relation: h.axbType,
2979
+ direction: h.direction,
2980
+ depth: h.depth,
2981
+ edgeCount: (h.edges ?? []).length,
2982
+ edges: (h.edges ?? []).map(summarizeEdge).filter(Boolean),
2983
+ truncated: h.truncated ?? false
2984
+ })
2985
+ ),
2974
2986
  totalReads: data.totalReads ?? 0,
2975
2987
  truncated: data.truncated ?? false
2976
2988
  };
@@ -3021,6 +3033,56 @@ function buildEdgeRecord(aType, aUid, axbType, bType, bUid, data) {
3021
3033
  };
3022
3034
  }
3023
3035
 
3036
+ // src/scope-path.ts
3037
+ function parseStorageScope(scope) {
3038
+ if (scope === "") return [];
3039
+ const parts = scope.split("/");
3040
+ if (parts.length % 2 !== 0) {
3041
+ throw new Error(
3042
+ `INVALID_SCOPE_PATH: storage-scope "${scope}" has an odd number of segments; expected interleaved <uid>/<name> pairs.`
3043
+ );
3044
+ }
3045
+ const out = [];
3046
+ for (let i = 0; i < parts.length; i += 2) {
3047
+ const uid = parts[i];
3048
+ const name = parts[i + 1];
3049
+ if (!uid || !name) {
3050
+ throw new Error(
3051
+ `INVALID_SCOPE_PATH: storage-scope "${scope}" contains an empty segment at position ${i}.`
3052
+ );
3053
+ }
3054
+ out.push({ uid, name });
3055
+ }
3056
+ return out;
3057
+ }
3058
+ function resolveAncestorScope(storageScope, uid) {
3059
+ if (!uid) return null;
3060
+ if (storageScope === "") return null;
3061
+ const parts = storageScope.split("/");
3062
+ for (let i = 0; i < parts.length; i += 2) {
3063
+ if (parts[i] === uid) {
3064
+ return i === 0 ? "" : parts.slice(0, i).join("/");
3065
+ }
3066
+ }
3067
+ return null;
3068
+ }
3069
+ function isAncestorScopeUid(storageScope, uid) {
3070
+ return resolveAncestorScope(storageScope, uid) !== null;
3071
+ }
3072
+ function appendStorageScope(parentScope, uid, name) {
3073
+ if (!uid || uid.includes("/")) {
3074
+ throw new Error(
3075
+ `INVALID_SCOPE_PATH: uid must be non-empty and must not contain "/": got "${uid}".`
3076
+ );
3077
+ }
3078
+ if (!name || name.includes("/")) {
3079
+ throw new Error(
3080
+ `INVALID_SCOPE_PATH: name must be non-empty and must not contain "/": got "${name}".`
3081
+ );
3082
+ }
3083
+ return parentScope ? `${parentScope}/${uid}/${name}` : `${uid}/${name}`;
3084
+ }
3085
+
3024
3086
  // src/index.ts
3025
3087
  init_serialization();
3026
3088
 
@@ -3228,7 +3290,6 @@ function getCustomElements() {
3228
3290
  function resilientView(ViewClass, tagName) {
3229
3291
  const g = globalThis;
3230
3292
  if (!g.HTMLElement) return ViewClass;
3231
- const Base = g.HTMLElement;
3232
3293
  const Wrapped = class extends ViewClass {
3233
3294
  connectedCallback() {
3234
3295
  try {
@@ -3316,6 +3377,7 @@ function defineViews(input) {
3316
3377
  // Annotate the CommonJS export names for ESM import in node:
3317
3378
  0 && (module.exports = {
3318
3379
  BOOTSTRAP_ENTRIES,
3380
+ CrossBackendTransactionError,
3319
3381
  DEFAULT_QUERY_LIMIT,
3320
3382
  DiscoveryError,
3321
3383
  DynamicRegistryError,
@@ -3337,6 +3399,7 @@ function defineViews(input) {
3337
3399
  TraversalError,
3338
3400
  ValidationError,
3339
3401
  analyzeQuerySafety,
3402
+ appendStorageScope,
3340
3403
  applyMigrationChain,
3341
3404
  buildEdgeQueryPlan,
3342
3405
  buildEdgeRecord,
@@ -3364,6 +3427,7 @@ function defineViews(input) {
3364
3427
  generateId,
3365
3428
  generateIndexConfig,
3366
3429
  generateTypes,
3430
+ isAncestorScopeUid,
3367
3431
  isAncestorUid,
3368
3432
  isTaggedValue,
3369
3433
  jsonSchemaToFieldMeta,
@@ -3371,8 +3435,10 @@ function defineViews(input) {
3371
3435
  matchScopeAny,
3372
3436
  migrateRecord,
3373
3437
  migrateRecords,
3438
+ parseStorageScope,
3374
3439
  precompileSource,
3375
3440
  resolveAncestorCollection,
3441
+ resolveAncestorScope,
3376
3442
  resolveView,
3377
3443
  serializeFirestoreTypes,
3378
3444
  validateMigrationChain