@dxos/effect 0.8.0 → 0.8.1-main.013e445

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.
@@ -18,12 +18,9 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var node_exports = {};
20
20
  __export(node_exports, {
21
- AST: () => import_schema.AST,
22
- JSONSchema: () => import_schema.JSONSchema,
23
21
  JsonPath: () => JsonPath,
24
22
  JsonProp: () => JsonProp,
25
23
  ParamKeyAnnotation: () => ParamKeyAnnotation,
26
- S: () => import_schema.Schema,
27
24
  SimpleType: () => SimpleType,
28
25
  UrlParser: () => UrlParser,
29
26
  VisitResult: () => VisitResult,
@@ -35,6 +32,7 @@ __export(node_exports, {
35
32
  getAnnotation: () => getAnnotation,
36
33
  getDiscriminatedType: () => getDiscriminatedType,
37
34
  getDiscriminatingProps: () => getDiscriminatingProps,
35
+ getField: () => getField,
38
36
  getParamKeyAnnotation: () => getParamKeyAnnotation,
39
37
  getSimpleType: () => getSimpleType,
40
38
  isDiscriminatedUnion: () => isDiscriminatedUnion,
@@ -47,35 +45,33 @@ __export(node_exports, {
47
45
  visit: () => visit
48
46
  });
49
47
  module.exports = __toCommonJS(node_exports);
50
- var import_schema = require("@effect/schema");
51
- var import_schema2 = require("@effect/schema");
52
48
  var import_effect = require("effect");
53
49
  var import_invariant = require("@dxos/invariant");
54
50
  var import_util = require("@dxos/util");
55
- var import_schema3 = require("@effect/schema");
51
+ var import_effect2 = require("effect");
56
52
  var import_Option = require("effect/Option");
53
+ var import_jsonpath_plus = require("jsonpath-plus");
57
54
  var import_invariant2 = require("@dxos/invariant");
58
- var import_schema4 = require("@effect/schema");
59
- var import_effect2 = require("effect");
55
+ var import_effect3 = require("effect");
60
56
  var import_util2 = require("@dxos/util");
61
57
  var __dxlog_file = "/home/runner/work/dxos/dxos/packages/common/effect/src/ast.ts";
62
58
  var getSimpleType = (node) => {
63
- if (import_schema2.AST.isObjectKeyword(node) || import_schema2.AST.isTypeLiteral(node) || isDiscriminatedUnion(node) || import_schema2.AST.isDeclaration(node)) {
59
+ if (import_effect.SchemaAST.isObjectKeyword(node) || import_effect.SchemaAST.isTypeLiteral(node) || isDiscriminatedUnion(node) || import_effect.SchemaAST.isDeclaration(node)) {
64
60
  return "object";
65
61
  }
66
- if (import_schema2.AST.isStringKeyword(node)) {
62
+ if (import_effect.SchemaAST.isStringKeyword(node)) {
67
63
  return "string";
68
64
  }
69
- if (import_schema2.AST.isNumberKeyword(node)) {
65
+ if (import_effect.SchemaAST.isNumberKeyword(node)) {
70
66
  return "number";
71
67
  }
72
- if (import_schema2.AST.isBooleanKeyword(node)) {
68
+ if (import_effect.SchemaAST.isBooleanKeyword(node)) {
73
69
  return "boolean";
74
70
  }
75
- if (import_schema2.AST.isEnums(node)) {
71
+ if (import_effect.SchemaAST.isEnums(node)) {
76
72
  return "enum";
77
73
  }
78
- if (import_schema2.AST.isLiteral(node)) {
74
+ if (import_effect.SchemaAST.isLiteral(node)) {
79
75
  return "literal";
80
76
  }
81
77
  };
@@ -125,8 +121,8 @@ var visitNode = (node, test, visitor, path = [], depth = 0) => {
125
121
  if (result !== 1) {
126
122
  visitor(node, path, depth);
127
123
  }
128
- if (import_schema2.AST.isTypeLiteral(node)) {
129
- for (const prop of import_schema2.AST.getPropertySignatures(node)) {
124
+ if (import_effect.SchemaAST.isTypeLiteral(node)) {
125
+ for (const prop of import_effect.SchemaAST.getPropertySignatures(node)) {
130
126
  const currentPath = [
131
127
  ...path,
132
128
  prop.name.toString()
@@ -136,7 +132,7 @@ var visitNode = (node, test, visitor, path = [], depth = 0) => {
136
132
  return result2;
137
133
  }
138
134
  }
139
- } else if (import_schema2.AST.isTupleType(node)) {
135
+ } else if (import_effect.SchemaAST.isTupleType(node)) {
140
136
  for (const [i, element] of node.elements.entries()) {
141
137
  const currentPath = [
142
138
  ...path,
@@ -147,14 +143,14 @@ var visitNode = (node, test, visitor, path = [], depth = 0) => {
147
143
  return result2;
148
144
  }
149
145
  }
150
- } else if (import_schema2.AST.isUnion(node)) {
146
+ } else if (import_effect.SchemaAST.isUnion(node)) {
151
147
  for (const type of node.types) {
152
148
  const result2 = visitNode(type, test, visitor, path, depth);
153
149
  if (result2 === 2) {
154
150
  return result2;
155
151
  }
156
152
  }
157
- } else if (import_schema2.AST.isRefinement(node)) {
153
+ } else if (import_effect.SchemaAST.isRefinement(node)) {
158
154
  const result2 = visitNode(node.from, test, visitor, path, depth);
159
155
  if (result2 === 2) {
160
156
  return result2;
@@ -164,21 +160,21 @@ var visitNode = (node, test, visitor, path = [], depth = 0) => {
164
160
  var findNode = (node, test) => {
165
161
  if (test(node)) {
166
162
  return node;
167
- } else if (import_schema2.AST.isTypeLiteral(node)) {
168
- for (const prop of import_schema2.AST.getPropertySignatures(node)) {
163
+ } else if (import_effect.SchemaAST.isTypeLiteral(node)) {
164
+ for (const prop of import_effect.SchemaAST.getPropertySignatures(node)) {
169
165
  const child = findNode(prop.type, test);
170
166
  if (child) {
171
167
  return child;
172
168
  }
173
169
  }
174
- } else if (import_schema2.AST.isTupleType(node)) {
170
+ } else if (import_effect.SchemaAST.isTupleType(node)) {
175
171
  for (const [_, element] of node.elements.entries()) {
176
172
  const child = findNode(element.type, test);
177
173
  if (child) {
178
174
  return child;
179
175
  }
180
176
  }
181
- } else if (import_schema2.AST.isUnion(node)) {
177
+ } else if (import_effect.SchemaAST.isUnion(node)) {
182
178
  if (isOption(node)) {
183
179
  for (const type of node.types) {
184
180
  const child = findNode(type, test);
@@ -187,24 +183,24 @@ var findNode = (node, test) => {
187
183
  }
188
184
  }
189
185
  }
190
- } else if (import_schema2.AST.isRefinement(node)) {
186
+ } else if (import_effect.SchemaAST.isRefinement(node)) {
191
187
  return findNode(node.from, test);
192
188
  }
193
189
  };
194
190
  var findProperty = (schema, path) => {
195
191
  const getProp = (node, path2) => {
196
192
  const [name, ...rest] = path2;
197
- const typeNode = findNode(node, import_schema2.AST.isTypeLiteral);
193
+ const typeNode = findNode(node, import_effect.SchemaAST.isTypeLiteral);
198
194
  (0, import_invariant.invariant)(typeNode, void 0, {
199
195
  F: __dxlog_file,
200
- L: 239,
196
+ L: 238,
201
197
  S: void 0,
202
198
  A: [
203
199
  "typeNode",
204
200
  ""
205
201
  ]
206
202
  });
207
- for (const prop of import_schema2.AST.getPropertySignatures(typeNode)) {
203
+ for (const prop of import_effect.SchemaAST.getPropertySignatures(typeNode)) {
208
204
  if (prop.name === name) {
209
205
  if (rest.length) {
210
206
  return getProp(prop.type, rest);
@@ -217,14 +213,14 @@ var findProperty = (schema, path) => {
217
213
  return getProp(schema.ast, path.split("."));
218
214
  };
219
215
  var defaultAnnotations = {
220
- ["ObjectKeyword"]: import_schema2.AST.objectKeyword,
221
- ["StringKeyword"]: import_schema2.AST.stringKeyword,
222
- ["NumberKeyword"]: import_schema2.AST.numberKeyword,
223
- ["BooleanKeyword"]: import_schema2.AST.booleanKeyword
216
+ ["ObjectKeyword"]: import_effect.SchemaAST.objectKeyword,
217
+ ["StringKeyword"]: import_effect.SchemaAST.stringKeyword,
218
+ ["NumberKeyword"]: import_effect.SchemaAST.numberKeyword,
219
+ ["BooleanKeyword"]: import_effect.SchemaAST.booleanKeyword
224
220
  };
225
221
  var getAnnotation = (annotationId, noDefault = true) => (node) => {
226
- const id = (0, import_effect.pipe)(import_schema2.AST.getIdentifierAnnotation(node), import_effect.Option.getOrUndefined);
227
- const value = (0, import_effect.pipe)(import_schema2.AST.getAnnotation(annotationId)(node), import_effect.Option.getOrUndefined);
222
+ const id = (0, import_effect.pipe)(import_effect.SchemaAST.getIdentifierAnnotation(node), import_effect.Option.getOrUndefined);
223
+ const value = (0, import_effect.pipe)(import_effect.SchemaAST.getAnnotation(annotationId)(node), import_effect.Option.getOrUndefined);
228
224
  if (noDefault && (value === defaultAnnotations[node._tag]?.annotations[annotationId] || value === id)) {
229
225
  return void 0;
230
226
  }
@@ -237,7 +233,7 @@ var findAnnotation = (node, annotationId, noDefault = true) => {
237
233
  if (value !== void 0) {
238
234
  return value;
239
235
  }
240
- if (import_schema2.AST.isUnion(node2)) {
236
+ if (import_effect.SchemaAST.isUnion(node2)) {
241
237
  if (isOption(node2)) {
242
238
  return getAnnotationById(node2.types[0]);
243
239
  }
@@ -246,18 +242,18 @@ var findAnnotation = (node, annotationId, noDefault = true) => {
246
242
  return getBaseAnnotation(node);
247
243
  };
248
244
  var isOption = (node) => {
249
- return import_schema2.AST.isUnion(node) && node.types.length === 2 && import_schema2.AST.isUndefinedKeyword(node.types[1]);
245
+ return import_effect.SchemaAST.isUnion(node) && node.types.length === 2 && import_effect.SchemaAST.isUndefinedKeyword(node.types[1]);
250
246
  };
251
247
  var isLiteralUnion = (node) => {
252
- return import_schema2.AST.isUnion(node) && node.types.every(import_schema2.AST.isLiteral);
248
+ return import_effect.SchemaAST.isUnion(node) && node.types.every(import_effect.SchemaAST.isLiteral);
253
249
  };
254
250
  var isDiscriminatedUnion = (node) => {
255
- return import_schema2.AST.isUnion(node) && !!getDiscriminatingProps(node)?.length;
251
+ return import_effect.SchemaAST.isUnion(node) && !!getDiscriminatingProps(node)?.length;
256
252
  };
257
253
  var getDiscriminatingProps = (node) => {
258
- (0, import_invariant.invariant)(import_schema2.AST.isUnion(node), void 0, {
254
+ (0, import_invariant.invariant)(import_effect.SchemaAST.isUnion(node), void 0, {
259
255
  F: __dxlog_file,
260
- L: 336,
256
+ L: 335,
261
257
  S: void 0,
262
258
  A: [
263
259
  "AST.isUnion(node)",
@@ -268,14 +264,14 @@ var getDiscriminatingProps = (node) => {
268
264
  return;
269
265
  }
270
266
  return node.types.reduce((shared, type) => {
271
- const props = import_schema2.AST.getPropertySignatures(type).filter((p) => import_schema2.AST.isLiteral(p.type)).map((p) => p.name.toString());
267
+ const props = import_effect.SchemaAST.getPropertySignatures(type).filter((p) => import_effect.SchemaAST.isLiteral(p.type)).map((p) => p.name.toString());
272
268
  return shared.length === 0 ? props : shared.filter((prop) => props.includes(prop));
273
269
  }, []);
274
270
  };
275
271
  var getDiscriminatedType = (node, value = {}) => {
276
- (0, import_invariant.invariant)(import_schema2.AST.isUnion(node), void 0, {
272
+ (0, import_invariant.invariant)(import_effect.SchemaAST.isUnion(node), void 0, {
277
273
  F: __dxlog_file,
278
- L: 357,
274
+ L: 356,
279
275
  S: void 0,
280
276
  A: [
281
277
  "AST.isUnion(node)",
@@ -284,7 +280,7 @@ var getDiscriminatedType = (node, value = {}) => {
284
280
  });
285
281
  (0, import_invariant.invariant)(value, void 0, {
286
282
  F: __dxlog_file,
287
- L: 358,
283
+ L: 357,
288
284
  S: void 0,
289
285
  A: [
290
286
  "value",
@@ -296,10 +292,10 @@ var getDiscriminatedType = (node, value = {}) => {
296
292
  return;
297
293
  }
298
294
  for (const type of node.types) {
299
- const match = import_schema2.AST.getPropertySignatures(type).filter((prop) => props?.includes(prop.name.toString())).every((prop) => {
300
- (0, import_invariant.invariant)(import_schema2.AST.isLiteral(prop.type), void 0, {
295
+ const match = import_effect.SchemaAST.getPropertySignatures(type).filter((prop) => props?.includes(prop.name.toString())).every((prop) => {
296
+ (0, import_invariant.invariant)(import_effect.SchemaAST.isLiteral(prop.type), void 0, {
301
297
  F: __dxlog_file,
302
- L: 369,
298
+ L: 368,
303
299
  S: void 0,
304
300
  A: [
305
301
  "AST.isLiteral(prop.type)",
@@ -314,10 +310,10 @@ var getDiscriminatedType = (node, value = {}) => {
314
310
  }
315
311
  const fields = Object.fromEntries(props.map((prop) => {
316
312
  const literals = node.types.map((type) => {
317
- const literal = import_schema2.AST.getPropertySignatures(type).find((p) => p.name.toString() === prop);
318
- (0, import_invariant.invariant)(import_schema2.AST.isLiteral(literal.type), void 0, {
313
+ const literal = import_effect.SchemaAST.getPropertySignatures(type).find((p) => p.name.toString() === prop);
314
+ (0, import_invariant.invariant)(import_effect.SchemaAST.isLiteral(literal.type), void 0, {
319
315
  F: __dxlog_file,
320
- L: 387,
316
+ L: 386,
321
317
  S: void 0,
322
318
  A: [
323
319
  "AST.isLiteral(literal.type)",
@@ -328,23 +324,23 @@ var getDiscriminatedType = (node, value = {}) => {
328
324
  }).filter(import_util.isNonNullable);
329
325
  return literals.length ? [
330
326
  prop,
331
- import_schema2.Schema.Literal(...literals)
327
+ import_effect.Schema.Literal(...literals)
332
328
  ] : void 0;
333
329
  }).filter(import_util.isNonNullable));
334
- const schema = import_schema2.Schema.Struct(fields);
330
+ const schema = import_effect.Schema.Struct(fields);
335
331
  return schema.ast;
336
332
  };
337
333
  var mapAst = (ast, f) => {
338
334
  switch (ast._tag) {
339
335
  case "TypeLiteral":
340
- return new import_schema2.AST.TypeLiteral(ast.propertySignatures.map((prop) => new import_schema2.AST.PropertySignature(prop.name, f(prop.type, prop.name), prop.isOptional, prop.isReadonly, prop.annotations)), ast.indexSignatures);
336
+ return new import_effect.SchemaAST.TypeLiteral(ast.propertySignatures.map((prop) => new import_effect.SchemaAST.PropertySignature(prop.name, f(prop.type, prop.name), prop.isOptional, prop.isReadonly, prop.annotations)), ast.indexSignatures);
341
337
  case "Union":
342
- return import_schema2.AST.Union.make(ast.types.map(f), ast.annotations);
338
+ return import_effect.SchemaAST.Union.make(ast.types.map(f), ast.annotations);
343
339
  case "TupleType":
344
- return new import_schema2.AST.TupleType(ast.elements.map((t, index) => new import_schema2.AST.OptionalType(f(t.type, index), t.isOptional, t.annotations)), ast.rest.map((t) => new import_schema2.AST.Type(f(t.type, void 0), t.annotations)), ast.isReadonly, ast.annotations);
340
+ return new import_effect.SchemaAST.TupleType(ast.elements.map((t, index) => new import_effect.SchemaAST.OptionalType(f(t.type, index), t.isOptional, t.annotations)), ast.rest.map((t) => new import_effect.SchemaAST.Type(f(t.type, void 0), t.annotations)), ast.isReadonly, ast.annotations);
345
341
  case "Suspend": {
346
342
  const newAst = f(ast.f(), void 0);
347
- return new import_schema2.AST.Suspend(() => newAst, ast.annotations);
343
+ return new import_effect.SchemaAST.Suspend(() => newAst, ast.annotations);
348
344
  }
349
345
  default:
350
346
  return ast;
@@ -353,10 +349,10 @@ var mapAst = (ast, f) => {
353
349
  var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/common/effect/src/jsonPath.ts";
354
350
  var PATH_REGEX = /^($|[a-zA-Z_$][\w$]*(?:\.[a-zA-Z_$][\w$]*|\[\d+\](?:\.)?)*$)/;
355
351
  var PROP_REGEX = /\w+/;
356
- var JsonPath = import_schema3.Schema.String.pipe(import_schema3.Schema.pattern(PATH_REGEX));
357
- var JsonProp = import_schema3.Schema.NonEmptyString.pipe(import_schema3.Schema.pattern(PROP_REGEX));
352
+ var JsonPath = import_effect2.Schema.String.pipe(import_effect2.Schema.pattern(PATH_REGEX));
353
+ var JsonProp = import_effect2.Schema.NonEmptyString.pipe(import_effect2.Schema.pattern(PROP_REGEX));
358
354
  var isJsonPath = (value) => {
359
- return (0, import_Option.isSome)(import_schema3.Schema.validateOption(JsonPath)(value));
355
+ return (0, import_Option.isSome)(import_effect2.Schema.validateOption(JsonPath)(value));
360
356
  };
361
357
  var createJsonPath = (path) => {
362
358
  const candidatePath = path.map((p, i) => {
@@ -368,7 +364,7 @@ var createJsonPath = (path) => {
368
364
  }).join("");
369
365
  (0, import_invariant2.invariant)(isJsonPath(candidatePath), `Invalid JsonPath: ${candidatePath}`, {
370
366
  F: __dxlog_file2,
371
- L: 56,
367
+ L: 57,
372
368
  S: void 0,
373
369
  A: [
374
370
  "isJsonPath(candidatePath)",
@@ -381,7 +377,7 @@ var fromEffectValidationPath = (effectPath) => {
381
377
  const jsonPath = effectPath.replace(/\.\[(\d+)\]/g, "[$1]");
382
378
  (0, import_invariant2.invariant)(isJsonPath(jsonPath), `Invalid JsonPath: ${jsonPath}`, {
383
379
  F: __dxlog_file2,
384
- L: 67,
380
+ L: 68,
385
381
  S: void 0,
386
382
  A: [
387
383
  "isJsonPath(jsonPath)",
@@ -396,8 +392,14 @@ var splitJsonPath = (path) => {
396
392
  }
397
393
  return path.match(/[a-zA-Z_$][\w$]*|\[\d+\]/g)?.map((part) => part.startsWith("[") ? part.replace(/[[\]]/g, "") : part) ?? [];
398
394
  };
395
+ var getField = (object, path) => {
396
+ return (0, import_jsonpath_plus.JSONPath)({
397
+ path,
398
+ json: object
399
+ })[0];
400
+ };
399
401
  var ParamKeyAnnotationId = Symbol.for("@dxos/schema/annotation/ParamKey");
400
- var getParamKeyAnnotation = import_schema4.AST.getAnnotation(ParamKeyAnnotationId);
402
+ var getParamKeyAnnotation = import_effect3.SchemaAST.getAnnotation(ParamKeyAnnotationId);
401
403
  var ParamKeyAnnotation = (value) => (self) => self.annotations({
402
404
  [ParamKeyAnnotationId]: value
403
405
  });
@@ -416,9 +418,9 @@ var UrlParser = class {
416
418
  value = url.searchParams.get(key);
417
419
  }
418
420
  if (value != null) {
419
- if (import_schema4.AST.isNumberKeyword(type.ast)) {
421
+ if (import_effect3.SchemaAST.isNumberKeyword(type.ast)) {
420
422
  params[key] = parseInt(value);
421
- } else if (import_schema4.AST.isBooleanKeyword(type.ast)) {
423
+ } else if (import_effect3.SchemaAST.isBooleanKeyword(type.ast)) {
422
424
  params[key] = value === "true" || value === "1";
423
425
  } else {
424
426
  params[key] = value;
@@ -436,7 +438,7 @@ var UrlParser = class {
436
438
  if (value !== void 0) {
437
439
  const field = this._schema.fields[key];
438
440
  if (field) {
439
- const { key: serializedKey } = (0, import_effect2.pipe)(getParamKeyAnnotation(field.ast), import_effect2.Option.getOrElse(() => ({
441
+ const { key: serializedKey } = (0, import_effect3.pipe)(getParamKeyAnnotation(field.ast), import_effect3.Option.getOrElse(() => ({
440
442
  key: (0, import_util2.decamelize)(key)
441
443
  })));
442
444
  url.searchParams.set(serializedKey, String(value));
@@ -448,12 +450,9 @@ var UrlParser = class {
448
450
  };
449
451
  // Annotate the CommonJS export names for ESM import in node:
450
452
  0 && (module.exports = {
451
- AST,
452
- JSONSchema,
453
453
  JsonPath,
454
454
  JsonProp,
455
455
  ParamKeyAnnotation,
456
- S,
457
456
  SimpleType,
458
457
  UrlParser,
459
458
  VisitResult,
@@ -465,6 +464,7 @@ var UrlParser = class {
465
464
  getAnnotation,
466
465
  getDiscriminatedType,
467
466
  getDiscriminatingProps,
467
+ getField,
468
468
  getParamKeyAnnotation,
469
469
  getSimpleType,
470
470
  isDiscriminatedUnion,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../../src/index.ts", "../../../src/ast.ts", "../../../src/jsonPath.ts", "../../../src/url.ts"],
4
- "sourcesContent": ["//\n// Copyright 2020 DXOS.org\n//\n\nimport { AST, JSONSchema, Schema as S } from '@effect/schema';\nimport type * as Types from 'effect/Types';\n\n// TODO(dmaretskyi): Remove re-exports.\nexport { AST, JSONSchema, S, Types };\n\nexport * from './ast';\nexport * from './jsonPath';\nexport * from './url';\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { AST, Schema as S } from '@effect/schema';\nimport { Option, pipe } from 'effect';\n\nimport { invariant } from '@dxos/invariant';\nimport { isNonNullable } from '@dxos/util';\n\nimport { type JsonPath, type JsonProp } from './jsonPath';\n\n//\n// Refs\n// https://effect.website/docs/schema/introduction\n// https://www.npmjs.com/package/@effect/schema\n// https://effect-ts.github.io/effect/schema/AST.ts.html\n//\n\nexport type SimpleType = 'object' | 'string' | 'number' | 'boolean' | 'enum' | 'literal';\n\n/**\n * Get the base type; e.g., traverse through refinements.\n */\nexport const getSimpleType = (node: AST.AST): SimpleType | undefined => {\n if (AST.isObjectKeyword(node) || AST.isTypeLiteral(node) || isDiscriminatedUnion(node) || AST.isDeclaration(node)) {\n return 'object';\n }\n\n if (AST.isStringKeyword(node)) {\n return 'string';\n }\n if (AST.isNumberKeyword(node)) {\n return 'number';\n }\n if (AST.isBooleanKeyword(node)) {\n return 'boolean';\n }\n\n if (AST.isEnums(node)) {\n return 'enum';\n }\n\n if (AST.isLiteral(node)) {\n return 'literal';\n }\n};\n\nexport const isSimpleType = (node: AST.AST): boolean => !!getSimpleType(node);\n\nexport namespace SimpleType {\n /**\n * Returns the default empty value for a given SimpleType.\n * Used for initializing new array values etc.\n */\n export const getDefaultValue = (type: SimpleType): any => {\n switch (type) {\n case 'string': {\n return '';\n }\n case 'number': {\n return 0;\n }\n case 'boolean': {\n return false;\n }\n case 'object': {\n return {};\n }\n default: {\n throw new Error(`Unsupported type for default value: ${type}`);\n }\n }\n };\n}\n\n//\n// Branded types\n//\n\nexport enum VisitResult {\n CONTINUE = 0,\n /**\n * Skip visiting children.\n */\n SKIP = 1,\n /**\n * Stop traversing immediately.\n */\n EXIT = 2,\n}\n\nexport type Path = (string | number)[];\n\nexport type TestFn = (node: AST.AST, path: Path, depth: number) => VisitResult | boolean | undefined;\n\nexport type VisitorFn = (node: AST.AST, path: Path, depth: number) => void;\n\nconst defaultTest: TestFn = isSimpleType;\n\n/**\n * Visit leaf nodes.\n * Refs:\n * - https://github.com/syntax-tree/unist-util-visit?tab=readme-ov-file#visitor\n * - https://github.com/syntax-tree/unist-util-is?tab=readme-ov-file#test\n */\nexport const visit: {\n (node: AST.AST, visitor: VisitorFn): void;\n (node: AST.AST, test: TestFn, visitor: VisitorFn): void;\n} = (node: AST.AST, testOrVisitor: TestFn | VisitorFn, visitor?: VisitorFn): void => {\n if (!visitor) {\n visitNode(node, defaultTest, testOrVisitor);\n } else {\n visitNode(node, testOrVisitor as TestFn, visitor);\n }\n};\n\nconst visitNode = (\n node: AST.AST,\n test: TestFn | undefined,\n visitor: VisitorFn,\n path: Path = [],\n depth = 0,\n): VisitResult | undefined => {\n const _result = test?.(node, path, depth);\n const result: VisitResult =\n _result === undefined\n ? VisitResult.CONTINUE\n : typeof _result === 'boolean'\n ? _result\n ? VisitResult.CONTINUE\n : VisitResult.SKIP\n : _result;\n\n if (result === VisitResult.EXIT) {\n return result;\n }\n if (result !== VisitResult.SKIP) {\n visitor(node, path, depth);\n }\n\n // Object.\n if (AST.isTypeLiteral(node)) {\n for (const prop of AST.getPropertySignatures(node)) {\n const currentPath = [...path, prop.name.toString()];\n const result = visitNode(prop.type, test, visitor, currentPath, depth + 1);\n if (result === VisitResult.EXIT) {\n return result;\n }\n }\n }\n\n // Array.\n else if (AST.isTupleType(node)) {\n for (const [i, element] of node.elements.entries()) {\n const currentPath = [...path, i];\n const result = visitNode(element.type, test, visitor, currentPath, depth);\n if (result === VisitResult.EXIT) {\n return result;\n }\n }\n }\n\n // Branching union (e.g., optional, discriminated unions).\n else if (AST.isUnion(node)) {\n for (const type of node.types) {\n const result = visitNode(type, test, visitor, path, depth);\n if (result === VisitResult.EXIT) {\n return result;\n }\n }\n }\n\n // Refinement.\n else if (AST.isRefinement(node)) {\n const result = visitNode(node.from, test, visitor, path, depth);\n if (result === VisitResult.EXIT) {\n return result;\n }\n }\n\n // TODO(burdon): Transforms?\n};\n\n/**\n * Recursively descend into AST to find first node that passes the test.\n */\n// TODO(burdon): Rewrite using visitNode?\nexport const findNode = (node: AST.AST, test: (node: AST.AST) => boolean): AST.AST | undefined => {\n if (test(node)) {\n return node;\n }\n\n // Object.\n else if (AST.isTypeLiteral(node)) {\n for (const prop of AST.getPropertySignatures(node)) {\n const child = findNode(prop.type, test);\n if (child) {\n return child;\n }\n }\n }\n\n // Tuple.\n else if (AST.isTupleType(node)) {\n for (const [_, element] of node.elements.entries()) {\n const child = findNode(element.type, test);\n if (child) {\n return child;\n }\n }\n }\n\n // Branching union (e.g., optional, discriminated unions).\n else if (AST.isUnion(node)) {\n if (isOption(node)) {\n for (const type of node.types) {\n const child = findNode(type, test);\n if (child) {\n return child;\n }\n }\n }\n }\n\n // Refinement.\n else if (AST.isRefinement(node)) {\n return findNode(node.from, test);\n }\n};\n\n/**\n * Get the AST node for the given property (dot-path).\n */\nexport const findProperty = (schema: S.Schema<any>, path: JsonPath | JsonProp): AST.AST | undefined => {\n const getProp = (node: AST.AST, path: JsonProp[]): AST.AST | undefined => {\n const [name, ...rest] = path;\n const typeNode = findNode(node, AST.isTypeLiteral);\n invariant(typeNode);\n for (const prop of AST.getPropertySignatures(typeNode)) {\n if (prop.name === name) {\n if (rest.length) {\n return getProp(prop.type, rest);\n } else {\n return prop.type;\n }\n }\n }\n };\n\n return getProp(schema.ast, path.split('.') as JsonProp[]);\n};\n\n//\n// Annotations\n//\n\nconst defaultAnnotations: Record<string, AST.Annotated> = {\n ['ObjectKeyword' as const]: AST.objectKeyword,\n ['StringKeyword' as const]: AST.stringKeyword,\n ['NumberKeyword' as const]: AST.numberKeyword,\n ['BooleanKeyword' as const]: AST.booleanKeyword,\n};\n\n/**\n * Get annotation or return undefined.\n * @param annotationId\n * @param noDefault If true, then return undefined for effect library defined values.\n */\nexport const getAnnotation =\n <T>(annotationId: symbol, noDefault = true) =>\n (node: AST.AST): T | undefined => {\n // Title fallback seems to be the identifier.\n const id = pipe(AST.getIdentifierAnnotation(node), Option.getOrUndefined);\n const value = pipe(AST.getAnnotation<T>(annotationId)(node), Option.getOrUndefined);\n if (noDefault && (value === defaultAnnotations[node._tag]?.annotations[annotationId] || value === id)) {\n return undefined;\n }\n\n return value;\n };\n\n/**\n * Recursively descend into AST to find first matching annotations.\n * Optionally skips default annotations for basic types (e.g., 'a string').\n */\n// TODO(burdon): Convert to effect pattern (i.e., return operator like getAnnotation).\nexport const findAnnotation = <T>(node: AST.AST, annotationId: symbol, noDefault = true): T | undefined => {\n const getAnnotationById = getAnnotation(annotationId, noDefault);\n\n const getBaseAnnotation = (node: AST.AST): T | undefined => {\n const value = getAnnotationById(node);\n if (value !== undefined) {\n return value as T;\n }\n\n if (AST.isUnion(node)) {\n if (isOption(node)) {\n return getAnnotationById(node.types[0]) as T;\n }\n }\n };\n\n return getBaseAnnotation(node);\n};\n\n//\n// Unions\n//\n\n/**\n * Effect S.optional creates a union type with undefined as the second type.\n */\nexport const isOption = (node: AST.AST): boolean => {\n return AST.isUnion(node) && node.types.length === 2 && AST.isUndefinedKeyword(node.types[1]);\n};\n\n/**\n * Determines if the node is a union of literal types.\n */\nexport const isLiteralUnion = (node: AST.AST): boolean => {\n return AST.isUnion(node) && node.types.every(AST.isLiteral);\n};\n\n/**\n * Determines if the node is a discriminated union.\n */\nexport const isDiscriminatedUnion = (node: AST.AST): boolean => {\n return AST.isUnion(node) && !!getDiscriminatingProps(node)?.length;\n};\n\n/**\n * Get the discriminating properties for the given union type.\n */\nexport const getDiscriminatingProps = (node: AST.AST): string[] | undefined => {\n invariant(AST.isUnion(node));\n if (isOption(node)) {\n return;\n }\n\n // Get common literals across all types.\n return node.types.reduce<string[]>((shared, type) => {\n const props = AST.getPropertySignatures(type)\n // TODO(burdon): Should check each literal is unique.\n .filter((p) => AST.isLiteral(p.type))\n .map((p) => p.name.toString());\n\n // Return common literals.\n return shared.length === 0 ? props : shared.filter((prop) => props.includes(prop));\n }, []);\n};\n\n/**\n * Get the discriminated type for the given value.\n */\nexport const getDiscriminatedType = (node: AST.AST, value: Record<string, any> = {}): AST.AST | undefined => {\n invariant(AST.isUnion(node));\n invariant(value);\n const props = getDiscriminatingProps(node);\n if (!props?.length) {\n return;\n }\n\n // Match provided values.\n for (const type of node.types) {\n const match = AST.getPropertySignatures(type)\n .filter((prop) => props?.includes(prop.name.toString()))\n .every((prop) => {\n invariant(AST.isLiteral(prop.type));\n return prop.type.literal === value[prop.name.toString()];\n });\n\n if (match) {\n return type;\n }\n }\n\n // Create union of discriminating properties.\n // NOTE: This may not work with non-overlapping variants.\n // TODO(burdon): Iterate through props and knock-out variants that don't match.\n const fields = Object.fromEntries(\n props\n .map((prop) => {\n const literals = node.types\n .map((type) => {\n const literal = AST.getPropertySignatures(type).find((p) => p.name.toString() === prop)!;\n invariant(AST.isLiteral(literal.type));\n return literal.type.literal;\n })\n .filter(isNonNullable);\n\n return literals.length ? [prop, S.Literal(...literals)] : undefined;\n })\n .filter(isNonNullable),\n );\n\n const schema = S.Struct(fields);\n return schema.ast;\n};\n\n/**\n * Maps AST nodes.\n * The user is responsible for recursively calling {@link mapAst} on the AST.\n * NOTE: Will evaluate suspended ASTs.\n */\nexport const mapAst = (ast: AST.AST, f: (ast: AST.AST, key: keyof any | undefined) => AST.AST): AST.AST => {\n switch (ast._tag) {\n case 'TypeLiteral':\n return new AST.TypeLiteral(\n ast.propertySignatures.map(\n (prop) =>\n new AST.PropertySignature(\n prop.name,\n f(prop.type, prop.name),\n prop.isOptional,\n prop.isReadonly,\n prop.annotations,\n ),\n ),\n ast.indexSignatures,\n );\n case 'Union':\n return AST.Union.make(ast.types.map(f), ast.annotations);\n case 'TupleType':\n return new AST.TupleType(\n ast.elements.map((t, index) => new AST.OptionalType(f(t.type, index), t.isOptional, t.annotations)),\n ast.rest.map((t) => new AST.Type(f(t.type, undefined), t.annotations)),\n ast.isReadonly,\n ast.annotations,\n );\n case 'Suspend': {\n const newAst = f(ast.f(), undefined);\n return new AST.Suspend(() => newAst, ast.annotations);\n }\n default:\n // TODO(dmaretskyi): Support more nodes.\n return ast;\n }\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Schema as S } from '@effect/schema';\nimport { isSome } from 'effect/Option';\n\nimport { invariant } from '@dxos/invariant';\n\nexport type JsonProp = string & { __JsonPath: true; __JsonProp: true };\nexport type JsonPath = string & { __JsonPath: true };\n\nconst PATH_REGEX = /^($|[a-zA-Z_$][\\w$]*(?:\\.[a-zA-Z_$][\\w$]*|\\[\\d+\\](?:\\.)?)*$)/;\nconst PROP_REGEX = /\\w+/;\n\n/**\n * https://www.ietf.org/archive/id/draft-goessner-dispatch-jsonpath-00.html\n */\nexport const JsonPath = S.String.pipe(S.pattern(PATH_REGEX)) as any as S.Schema<JsonPath>;\nexport const JsonProp = S.NonEmptyString.pipe(S.pattern(PROP_REGEX)) as any as S.Schema<JsonProp>;\n\nexport const isJsonPath = (value: unknown): value is JsonPath => {\n return isSome(S.validateOption(JsonPath)(value));\n};\n\n/**\n * Creates a JsonPath from an array of path segments.\n *\n * Currently supports:\n * - Simple property access (e.g., 'foo.bar')\n * - Array indexing with non-negative integers (e.g., 'foo[0]')\n * - Identifiers starting with letters, underscore, or $ (e.g., '$foo', '_bar')\n * - Dot notation for nested properties (e.g., 'foo.bar.baz')\n *\n * Does not support (yet?).\n * - Recursive descent (..)\n * - Wildcards (*)\n * - Array slicing\n * - Filters\n * - Negative indices\n *\n * @param path Array of string or number segments\n * @returns Valid JsonPath or undefined if invalid\n */\nexport const createJsonPath = (path: (string | number)[]): JsonPath => {\n const candidatePath = path\n .map((p, i) => {\n if (typeof p === 'number') {\n return `[${p}]`;\n } else {\n return i === 0 ? p : `.${p}`;\n }\n })\n .join('');\n\n invariant(isJsonPath(candidatePath), `Invalid JsonPath: ${candidatePath}`);\n return candidatePath;\n};\n\n/**\n * Converts Effect validation path format (e.g. \"addresses.[0].zip\")\n * to JsonPath format (e.g. \"addresses[0].zip\")\n */\nexport const fromEffectValidationPath = (effectPath: string): JsonPath => {\n // Handle array notation: convert \"prop.[0]\" to \"prop[0]\"\n const jsonPath = effectPath.replace(/\\.\\[(\\d+)\\]/g, '[$1]');\n invariant(isJsonPath(jsonPath), `Invalid JsonPath: ${jsonPath}`);\n return jsonPath;\n};\n\n/**\n * Splits a JsonPath into its constituent parts.\n * Handles property access and array indexing.\n */\nexport const splitJsonPath = (path: JsonPath): string[] => {\n if (!isJsonPath(path)) {\n return [];\n }\n\n return (\n path\n .match(/[a-zA-Z_$][\\w$]*|\\[\\d+\\]/g)\n ?.map((part) => (part.startsWith('[') ? part.replace(/[[\\]]/g, '') : part)) ?? []\n );\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { AST, type Schema as S } from '@effect/schema';\nimport { Option, pipe } from 'effect';\n\nimport { decamelize } from '@dxos/util';\n\nconst ParamKeyAnnotationId = Symbol.for('@dxos/schema/annotation/ParamKey');\n\ntype ParamKeyAnnotationValue = { key: string };\n\nexport const getParamKeyAnnotation: (annotated: AST.Annotated) => Option.Option<ParamKeyAnnotationValue> =\n AST.getAnnotation<ParamKeyAnnotationValue>(ParamKeyAnnotationId);\n\nexport const ParamKeyAnnotation =\n (value: ParamKeyAnnotationValue) =>\n <S extends S.Annotable.All>(self: S): S.Annotable.Self<S> =>\n self.annotations({ [ParamKeyAnnotationId]: value });\n\n/**\n * HTTP params parser.\n * Supports custom key serialization.\n */\nexport class UrlParser<T extends Record<string, any>> {\n constructor(private readonly _schema: S.Struct<T>) {}\n\n /**\n * Parse URL params.\n */\n parse(_url: string): T {\n const url = new URL(_url);\n return Object.entries(this._schema.fields).reduce<Record<string, any>>((params, [key, type]) => {\n let value = url.searchParams.get(decamelize(key));\n if (value == null) {\n value = url.searchParams.get(key);\n }\n\n if (value != null) {\n if (AST.isNumberKeyword(type.ast)) {\n params[key] = parseInt(value);\n } else if (AST.isBooleanKeyword(type.ast)) {\n params[key] = value === 'true' || value === '1';\n } else {\n params[key] = value;\n }\n }\n\n return params;\n }, {}) as T;\n }\n\n /**\n * Return URL with encoded params.\n */\n create(_url: string, params: T): URL {\n const url = new URL(_url);\n Object.entries(params).forEach(([key, value]) => {\n if (value !== undefined) {\n const field = this._schema.fields[key];\n if (field) {\n const { key: serializedKey } = pipe(\n getParamKeyAnnotation(field.ast),\n Option.getOrElse(() => ({\n key: decamelize(key),\n })),\n );\n\n url.searchParams.set(serializedKey, String(value));\n }\n }\n });\n\n return url;\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,oBAA6C;ACA7C,IAAAA,iBAAiC;AACjC,oBAA6B;AAE7B,uBAA0B;AAC1B,kBAA8B;ACJ9B,IAAAA,iBAA4B;AAC5B,oBAAuB;AAEvB,IAAAC,oBAA0B;ACH1B,IAAAD,iBAAsC;AACtC,IAAAE,iBAA6B;AAE7B,IAAAC,eAA2B;;AFiBpB,IAAMC,gBAAgB,CAACC,SAAAA;AAC5B,MAAIC,mBAAIC,gBAAgBF,IAAAA,KAASC,mBAAIE,cAAcH,IAAAA,KAASI,qBAAqBJ,IAAAA,KAASC,mBAAII,cAAcL,IAAAA,GAAO;AACjH,WAAO;EACT;AAEA,MAAIC,mBAAIK,gBAAgBN,IAAAA,GAAO;A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AAQ,CAAC,CAACN,KAAKhF,KAAAA,MAAM;AAC1C,UAAIA,UAAUzC,QAAW;AACvB,cAAMgI,QAAQ,KAAKb,QAAQtD,OAAO4D,GAAAA;AAClC,YAAIO,OAAO;AACT,gBAAM,EAAEP,KAAKQ,cAAa,QAAK5F,eAAAA,MAC7ByE,sBAAsBkB,MAAMtG,GAAG,GAC/Ba,eAAAA,OAAO2F,UAAU,OAAO;YACtBT,SAAKG,yBAAWH,GAAAA;UAClB,EAAA,CAAA;AAGFH,cAAII,aAAaS,IAAIF,eAAevC,OAAOjD,KAAAA,CAAAA;QAC7C;MACF;IACF,CAAA;AAEA,WAAO6E;EACT;AACF;",
6
- "names": ["import_schema", "import_invariant", "import_effect", "import_util", "getSimpleType", "node", "AST", "isObjectKeyword", "isTypeLiteral", "isDiscriminatedUnion", "isDeclaration", "isStringKeyword", "isNumberKeyword", "isBooleanKeyword", "isEnums", "isLiteral", "isSimpleType", "SimpleType", "getDefaultValue", "type", "Error", "VisitResult", "defaultTest", "visit", "testOrVisitor", "visitor", "visitNode", "test", "path", "depth", "_result", "result", "undefined", "prop", "getPropertySignatures", "currentPath", "name", "toString", "isTupleType", "i", "element", "elements", "entries", "isUnion", "types", "isRefinement", "from", "findNode", "child", "_", "isOption", "findProperty", "schema", "getProp", "rest", "typeNode", "invariant", "length", "ast", "split", "defaultAnnotations", "objectKeyword", "stringKeyword", "numberKeyword", "booleanKeyword", "getAnnotation", "annotationId", "noDefault", "id", "pipe", "getIdentifierAnnotation", "Option", "getOrUndefined", "value", "_tag", "annotations", "findAnnotation", "getAnnotationById", "getBaseAnnotation", "isUndefinedKeyword", "isLiteralUnion", "every", "getDiscriminatingProps", "reduce", "shared", "props", "filter", "p", "map", "includes", "getDiscriminatedType", "match", "literal", "fields", "Object", "fromEntries", "literals", "find", "isNonNullable", "S", "Literal", "Struct", "mapAst", "f", "TypeLiteral", "propertySignatures", "PropertySignature", "isOptional", "isReadonly", "indexSignatures", "Union", "make", "TupleType", "t", "index", "OptionalType", "Type", "newAst", "Suspend", "PATH_REGEX", "PROP_REGEX", "JsonPath", "String", "pattern", "JsonProp", "NonEmptyString", "isJsonPath", "isSome", "validateOption", "createJsonPath", "candidatePath", "join", "fromEffectValidationPath", "effectPath", "jsonPath", "replace", "splitJsonPath", "part", "startsWith", "ParamKeyAnnotationId", "Symbol", "for", "getParamKeyAnnotation", "ParamKeyAnnotation", "self", "UrlParser", "constructor", "_schema", "parse", "_url", "url", "URL", "params", "key", "searchParams", "get", "decamelize", "parseInt", "create", "forEach", "field", "serializedKey", "getOrElse", "set"]
3
+ "sources": ["../../../src/ast.ts", "../../../src/jsonPath.ts", "../../../src/url.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { Option, pipe, SchemaAST as AST, Schema as S } from 'effect';\n\nimport { invariant } from '@dxos/invariant';\nimport { isNonNullable } from '@dxos/util';\n\nimport { type JsonPath, type JsonProp } from './jsonPath';\n\n//\n// Refs\n// https://effect.website/docs/schema/introduction\n// https://www.npmjs.com/package/@effect/schema\n// https://effect-ts.github.io/effect/schema/AST.ts.html\n//\n\nexport type SimpleType = 'object' | 'string' | 'number' | 'boolean' | 'enum' | 'literal';\n\n/**\n * Get the base type; e.g., traverse through refinements.\n */\nexport const getSimpleType = (node: AST.AST): SimpleType | undefined => {\n if (AST.isObjectKeyword(node) || AST.isTypeLiteral(node) || isDiscriminatedUnion(node) || AST.isDeclaration(node)) {\n return 'object';\n }\n\n if (AST.isStringKeyword(node)) {\n return 'string';\n }\n if (AST.isNumberKeyword(node)) {\n return 'number';\n }\n if (AST.isBooleanKeyword(node)) {\n return 'boolean';\n }\n\n if (AST.isEnums(node)) {\n return 'enum';\n }\n\n if (AST.isLiteral(node)) {\n return 'literal';\n }\n};\n\nexport const isSimpleType = (node: AST.AST): boolean => !!getSimpleType(node);\n\nexport namespace SimpleType {\n /**\n * Returns the default empty value for a given SimpleType.\n * Used for initializing new array values etc.\n */\n export const getDefaultValue = (type: SimpleType): any => {\n switch (type) {\n case 'string': {\n return '';\n }\n case 'number': {\n return 0;\n }\n case 'boolean': {\n return false;\n }\n case 'object': {\n return {};\n }\n default: {\n throw new Error(`Unsupported type for default value: ${type}`);\n }\n }\n };\n}\n\n//\n// Branded types\n//\n\nexport enum VisitResult {\n CONTINUE = 0,\n /**\n * Skip visiting children.\n */\n SKIP = 1,\n /**\n * Stop traversing immediately.\n */\n EXIT = 2,\n}\n\nexport type Path = (string | number)[];\n\nexport type TestFn = (node: AST.AST, path: Path, depth: number) => VisitResult | boolean | undefined;\n\nexport type VisitorFn = (node: AST.AST, path: Path, depth: number) => void;\n\nconst defaultTest: TestFn = isSimpleType;\n\n/**\n * Visit leaf nodes.\n * Refs:\n * - https://github.com/syntax-tree/unist-util-visit?tab=readme-ov-file#visitor\n * - https://github.com/syntax-tree/unist-util-is?tab=readme-ov-file#test\n */\nexport const visit: {\n (node: AST.AST, visitor: VisitorFn): void;\n (node: AST.AST, test: TestFn, visitor: VisitorFn): void;\n} = (node: AST.AST, testOrVisitor: TestFn | VisitorFn, visitor?: VisitorFn): void => {\n if (!visitor) {\n visitNode(node, defaultTest, testOrVisitor);\n } else {\n visitNode(node, testOrVisitor as TestFn, visitor);\n }\n};\n\nconst visitNode = (\n node: AST.AST,\n test: TestFn | undefined,\n visitor: VisitorFn,\n path: Path = [],\n depth = 0,\n): VisitResult | undefined => {\n const _result = test?.(node, path, depth);\n const result: VisitResult =\n _result === undefined\n ? VisitResult.CONTINUE\n : typeof _result === 'boolean'\n ? _result\n ? VisitResult.CONTINUE\n : VisitResult.SKIP\n : _result;\n\n if (result === VisitResult.EXIT) {\n return result;\n }\n if (result !== VisitResult.SKIP) {\n visitor(node, path, depth);\n }\n\n // Object.\n if (AST.isTypeLiteral(node)) {\n for (const prop of AST.getPropertySignatures(node)) {\n const currentPath = [...path, prop.name.toString()];\n const result = visitNode(prop.type, test, visitor, currentPath, depth + 1);\n if (result === VisitResult.EXIT) {\n return result;\n }\n }\n }\n\n // Array.\n else if (AST.isTupleType(node)) {\n for (const [i, element] of node.elements.entries()) {\n const currentPath = [...path, i];\n const result = visitNode(element.type, test, visitor, currentPath, depth);\n if (result === VisitResult.EXIT) {\n return result;\n }\n }\n }\n\n // Branching union (e.g., optional, discriminated unions).\n else if (AST.isUnion(node)) {\n for (const type of node.types) {\n const result = visitNode(type, test, visitor, path, depth);\n if (result === VisitResult.EXIT) {\n return result;\n }\n }\n }\n\n // Refinement.\n else if (AST.isRefinement(node)) {\n const result = visitNode(node.from, test, visitor, path, depth);\n if (result === VisitResult.EXIT) {\n return result;\n }\n }\n\n // TODO(burdon): Transforms?\n};\n\n/**\n * Recursively descend into AST to find first node that passes the test.\n */\n// TODO(burdon): Rewrite using visitNode?\nexport const findNode = (node: AST.AST, test: (node: AST.AST) => boolean): AST.AST | undefined => {\n if (test(node)) {\n return node;\n }\n\n // Object.\n else if (AST.isTypeLiteral(node)) {\n for (const prop of AST.getPropertySignatures(node)) {\n const child = findNode(prop.type, test);\n if (child) {\n return child;\n }\n }\n }\n\n // Tuple.\n else if (AST.isTupleType(node)) {\n for (const [_, element] of node.elements.entries()) {\n const child = findNode(element.type, test);\n if (child) {\n return child;\n }\n }\n }\n\n // Branching union (e.g., optional, discriminated unions).\n else if (AST.isUnion(node)) {\n if (isOption(node)) {\n for (const type of node.types) {\n const child = findNode(type, test);\n if (child) {\n return child;\n }\n }\n }\n }\n\n // Refinement.\n else if (AST.isRefinement(node)) {\n return findNode(node.from, test);\n }\n};\n\n/**\n * Get the AST node for the given property (dot-path).\n */\nexport const findProperty = (schema: S.Schema.AnyNoContext, path: JsonPath | JsonProp): AST.AST | undefined => {\n const getProp = (node: AST.AST, path: JsonProp[]): AST.AST | undefined => {\n const [name, ...rest] = path;\n const typeNode = findNode(node, AST.isTypeLiteral);\n invariant(typeNode);\n for (const prop of AST.getPropertySignatures(typeNode)) {\n if (prop.name === name) {\n if (rest.length) {\n return getProp(prop.type, rest);\n } else {\n return prop.type;\n }\n }\n }\n };\n\n return getProp(schema.ast, path.split('.') as JsonProp[]);\n};\n\n//\n// Annotations\n//\n\nconst defaultAnnotations: Record<string, AST.Annotated> = {\n ['ObjectKeyword' as const]: AST.objectKeyword,\n ['StringKeyword' as const]: AST.stringKeyword,\n ['NumberKeyword' as const]: AST.numberKeyword,\n ['BooleanKeyword' as const]: AST.booleanKeyword,\n};\n\n/**\n * Get annotation or return undefined.\n * @param annotationId\n * @param noDefault If true, then return undefined for effect library defined values.\n */\nexport const getAnnotation =\n <T>(annotationId: symbol, noDefault = true) =>\n (node: AST.AST): T | undefined => {\n // Title fallback seems to be the identifier.\n const id = pipe(AST.getIdentifierAnnotation(node), Option.getOrUndefined);\n const value = pipe(AST.getAnnotation<T>(annotationId)(node), Option.getOrUndefined);\n if (noDefault && (value === defaultAnnotations[node._tag]?.annotations[annotationId] || value === id)) {\n return undefined;\n }\n\n return value;\n };\n\n/**\n * Recursively descend into AST to find first matching annotations.\n * Optionally skips default annotations for basic types (e.g., 'a string').\n */\n// TODO(burdon): Convert to effect pattern (i.e., return operator like getAnnotation).\nexport const findAnnotation = <T>(node: AST.AST, annotationId: symbol, noDefault = true): T | undefined => {\n const getAnnotationById = getAnnotation(annotationId, noDefault);\n\n const getBaseAnnotation = (node: AST.AST): T | undefined => {\n const value = getAnnotationById(node);\n if (value !== undefined) {\n return value as T;\n }\n\n if (AST.isUnion(node)) {\n if (isOption(node)) {\n return getAnnotationById(node.types[0]) as T;\n }\n }\n };\n\n return getBaseAnnotation(node);\n};\n\n//\n// Unions\n//\n\n/**\n * Effect S.optional creates a union type with undefined as the second type.\n */\nexport const isOption = (node: AST.AST): boolean => {\n return AST.isUnion(node) && node.types.length === 2 && AST.isUndefinedKeyword(node.types[1]);\n};\n\n/**\n * Determines if the node is a union of literal types.\n */\nexport const isLiteralUnion = (node: AST.AST): boolean => {\n return AST.isUnion(node) && node.types.every(AST.isLiteral);\n};\n\n/**\n * Determines if the node is a discriminated union.\n */\nexport const isDiscriminatedUnion = (node: AST.AST): boolean => {\n return AST.isUnion(node) && !!getDiscriminatingProps(node)?.length;\n};\n\n/**\n * Get the discriminating properties for the given union type.\n */\nexport const getDiscriminatingProps = (node: AST.AST): string[] | undefined => {\n invariant(AST.isUnion(node));\n if (isOption(node)) {\n return;\n }\n\n // Get common literals across all types.\n return node.types.reduce<string[]>((shared, type) => {\n const props = AST.getPropertySignatures(type)\n // TODO(burdon): Should check each literal is unique.\n .filter((p) => AST.isLiteral(p.type))\n .map((p) => p.name.toString());\n\n // Return common literals.\n return shared.length === 0 ? props : shared.filter((prop) => props.includes(prop));\n }, []);\n};\n\n/**\n * Get the discriminated type for the given value.\n */\nexport const getDiscriminatedType = (node: AST.AST, value: Record<string, any> = {}): AST.AST | undefined => {\n invariant(AST.isUnion(node));\n invariant(value);\n const props = getDiscriminatingProps(node);\n if (!props?.length) {\n return;\n }\n\n // Match provided values.\n for (const type of node.types) {\n const match = AST.getPropertySignatures(type)\n .filter((prop) => props?.includes(prop.name.toString()))\n .every((prop) => {\n invariant(AST.isLiteral(prop.type));\n return prop.type.literal === value[prop.name.toString()];\n });\n\n if (match) {\n return type;\n }\n }\n\n // Create union of discriminating properties.\n // NOTE: This may not work with non-overlapping variants.\n // TODO(burdon): Iterate through props and knock-out variants that don't match.\n const fields = Object.fromEntries(\n props\n .map((prop) => {\n const literals = node.types\n .map((type) => {\n const literal = AST.getPropertySignatures(type).find((p) => p.name.toString() === prop)!;\n invariant(AST.isLiteral(literal.type));\n return literal.type.literal;\n })\n .filter(isNonNullable);\n\n return literals.length ? [prop, S.Literal(...literals)] : undefined;\n })\n .filter(isNonNullable),\n );\n\n const schema = S.Struct(fields);\n return schema.ast;\n};\n\n/**\n * Maps AST nodes.\n * The user is responsible for recursively calling {@link mapAst} on the AST.\n * NOTE: Will evaluate suspended ASTs.\n */\nexport const mapAst = (ast: AST.AST, f: (ast: AST.AST, key: keyof any | undefined) => AST.AST): AST.AST => {\n switch (ast._tag) {\n case 'TypeLiteral':\n return new AST.TypeLiteral(\n ast.propertySignatures.map(\n (prop) =>\n new AST.PropertySignature(\n prop.name,\n f(prop.type, prop.name),\n prop.isOptional,\n prop.isReadonly,\n prop.annotations,\n ),\n ),\n ast.indexSignatures,\n );\n case 'Union':\n return AST.Union.make(ast.types.map(f), ast.annotations);\n case 'TupleType':\n return new AST.TupleType(\n ast.elements.map((t, index) => new AST.OptionalType(f(t.type, index), t.isOptional, t.annotations)),\n ast.rest.map((t) => new AST.Type(f(t.type, undefined), t.annotations)),\n ast.isReadonly,\n ast.annotations,\n );\n case 'Suspend': {\n const newAst = f(ast.f(), undefined);\n return new AST.Suspend(() => newAst, ast.annotations);\n }\n default:\n // TODO(dmaretskyi): Support more nodes.\n return ast;\n }\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Schema as S } from 'effect';\nimport { isSome } from 'effect/Option';\nimport { JSONPath } from 'jsonpath-plus';\n\nimport { invariant } from '@dxos/invariant';\n\nexport type JsonProp = string & { __JsonPath: true; __JsonProp: true };\nexport type JsonPath = string & { __JsonPath: true };\n\nconst PATH_REGEX = /^($|[a-zA-Z_$][\\w$]*(?:\\.[a-zA-Z_$][\\w$]*|\\[\\d+\\](?:\\.)?)*$)/;\nconst PROP_REGEX = /\\w+/;\n\n/**\n * https://www.ietf.org/archive/id/draft-goessner-dispatch-jsonpath-00.html\n */\nexport const JsonPath = S.String.pipe(S.pattern(PATH_REGEX)) as any as S.Schema<JsonPath>;\nexport const JsonProp = S.NonEmptyString.pipe(S.pattern(PROP_REGEX)) as any as S.Schema<JsonProp>;\n\nexport const isJsonPath = (value: unknown): value is JsonPath => {\n return isSome(S.validateOption(JsonPath)(value));\n};\n\n/**\n * Creates a JsonPath from an array of path segments.\n *\n * Currently supports:\n * - Simple property access (e.g., 'foo.bar')\n * - Array indexing with non-negative integers (e.g., 'foo[0]')\n * - Identifiers starting with letters, underscore, or $ (e.g., '$foo', '_bar')\n * - Dot notation for nested properties (e.g., 'foo.bar.baz')\n *\n * Does not support (yet?).\n * - Recursive descent (..)\n * - Wildcards (*)\n * - Array slicing\n * - Filters\n * - Negative indices\n *\n * @param path Array of string or number segments\n * @returns Valid JsonPath or undefined if invalid\n */\nexport const createJsonPath = (path: (string | number)[]): JsonPath => {\n const candidatePath = path\n .map((p, i) => {\n if (typeof p === 'number') {\n return `[${p}]`;\n } else {\n return i === 0 ? p : `.${p}`;\n }\n })\n .join('');\n\n invariant(isJsonPath(candidatePath), `Invalid JsonPath: ${candidatePath}`);\n return candidatePath;\n};\n\n/**\n * Converts Effect validation path format (e.g. \"addresses.[0].zip\")\n * to JsonPath format (e.g., \"addresses[0].zip\")\n */\nexport const fromEffectValidationPath = (effectPath: string): JsonPath => {\n // Handle array notation: convert \"prop.[0]\" to \"prop[0]\"\n const jsonPath = effectPath.replace(/\\.\\[(\\d+)\\]/g, '[$1]');\n invariant(isJsonPath(jsonPath), `Invalid JsonPath: ${jsonPath}`);\n return jsonPath;\n};\n\n/**\n * Splits a JsonPath into its constituent parts.\n * Handles property access and array indexing.\n */\nexport const splitJsonPath = (path: JsonPath): string[] => {\n if (!isJsonPath(path)) {\n return [];\n }\n\n return (\n path\n .match(/[a-zA-Z_$][\\w$]*|\\[\\d+\\]/g)\n ?.map((part) => (part.startsWith('[') ? part.replace(/[[\\]]/g, '') : part)) ?? []\n );\n};\n\n/**\n * Applies a JsonPath to an object.\n */\nexport const getField = (object: any, path: JsonPath): any => {\n // By default, JSONPath returns an array of results.\n return JSONPath({ path, json: object })[0];\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { SchemaAST as AST, type Schema as S, Option, pipe } from 'effect';\n\nimport { decamelize } from '@dxos/util';\n\nconst ParamKeyAnnotationId = Symbol.for('@dxos/schema/annotation/ParamKey');\n\ntype ParamKeyAnnotationValue = { key: string };\n\nexport const getParamKeyAnnotation: (annotated: AST.Annotated) => Option.Option<ParamKeyAnnotationValue> =\n AST.getAnnotation<ParamKeyAnnotationValue>(ParamKeyAnnotationId);\n\nexport const ParamKeyAnnotation =\n (value: ParamKeyAnnotationValue) =>\n <S extends S.Annotable.All>(self: S): S.Annotable.Self<S> =>\n self.annotations({ [ParamKeyAnnotationId]: value });\n\n/**\n * HTTP params parser.\n * Supports custom key serialization.\n */\nexport class UrlParser<T extends Record<string, any>> {\n constructor(private readonly _schema: S.Struct<T>) {}\n\n /**\n * Parse URL params.\n */\n parse(_url: string): T {\n const url = new URL(_url);\n return Object.entries(this._schema.fields).reduce<Record<string, any>>((params, [key, type]) => {\n let value = url.searchParams.get(decamelize(key));\n if (value == null) {\n value = url.searchParams.get(key);\n }\n\n if (value != null) {\n if (AST.isNumberKeyword(type.ast)) {\n params[key] = parseInt(value);\n } else if (AST.isBooleanKeyword(type.ast)) {\n params[key] = value === 'true' || value === '1';\n } else {\n params[key] = value;\n }\n }\n\n return params;\n }, {}) as T;\n }\n\n /**\n * Return URL with encoded params.\n */\n create(_url: string, params: T): URL {\n const url = new URL(_url);\n Object.entries(params).forEach(([key, value]) => {\n if (value !== undefined) {\n const field = this._schema.fields[key];\n if (field) {\n const { key: serializedKey } = pipe(\n getParamKeyAnnotation(field.ast),\n Option.getOrElse(() => ({\n key: decamelize(key),\n })),\n );\n\n url.searchParams.set(serializedKey, String(value));\n }\n }\n });\n\n return url;\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,oBAA4D;AAE5D,uBAA0B;AAC1B,kBAA8B;ACH9B,IAAAA,iBAA4B;AAC5B,oBAAuB;AACvB,2BAAyB;AAEzB,IAAAC,oBAA0B;ACJ1B,IAAAD,iBAAiE;AAEjE,IAAAE,eAA2B;;AFiBpB,IAAMC,gBAAgB,CAACC,SAAAA;AAC5B,MAAIC,cAAAA,UAAIC,gBAAgBF,IAAAA,KAASC,cAAAA,UAAIE,cAAcH,IAAAA,KAASI,qBAAqBJ,IAAAA,KAASC,cAAAA,UAAII,cAAcL,IAAAA,GAAO;AACjH,WAAO;EACT;A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;AACjB,YAAInE,eAAAA,UAAIM,gBAAgBO,KAAKuC,GAAG,GAAG;AACjCkG,iBAAOC,GAAAA,IAAOI,SAASxF,KAAAA;QACzB,WAAWnE,eAAAA,UAAIO,iBAAiBM,KAAKuC,GAAG,GAAG;AACzCkG,iBAAOC,GAAAA,IAAOpF,UAAU,UAAUA,UAAU;QAC9C,OAAO;AACLmF,iBAAOC,GAAAA,IAAOpF;QAChB;MACF;AAEA,aAAOmF;IACT,GAAG,CAAC,CAAA;EACN;;;;EAKAM,OAAOT,MAAcG,QAAgB;AACnC,UAAMF,MAAM,IAAIC,IAAIF,IAAAA;AACpB3D,WAAOpD,QAAQkH,MAAAA,EAAQO,QAAQ,CAAC,CAACN,KAAKpF,KAAAA,MAAM;AAC1C,UAAIA,UAAUzC,QAAW;AACvB,cAAMoI,QAAQ,KAAKb,QAAQ1D,OAAOgE,GAAAA;AAClC,YAAIO,OAAO;AACT,gBAAM,EAAEP,KAAKQ,cAAa,QAAKhG,eAAAA,MAC7B6E,sBAAsBkB,MAAM1G,GAAG,GAC/Ba,eAAAA,OAAO+F,UAAU,OAAO;YACtBT,SAAKG,yBAAWH,GAAAA;UAClB,EAAA,CAAA;AAGFH,cAAII,aAAaS,IAAIF,eAAe3C,OAAOjD,KAAAA,CAAAA;QAC7C;MACF;IACF,CAAA;AAEA,WAAOiF;EACT;AACF;",
6
+ "names": ["import_effect", "import_invariant", "import_util", "getSimpleType", "node", "AST", "isObjectKeyword", "isTypeLiteral", "isDiscriminatedUnion", "isDeclaration", "isStringKeyword", "isNumberKeyword", "isBooleanKeyword", "isEnums", "isLiteral", "isSimpleType", "SimpleType", "getDefaultValue", "type", "Error", "VisitResult", "defaultTest", "visit", "testOrVisitor", "visitor", "visitNode", "test", "path", "depth", "_result", "result", "undefined", "prop", "getPropertySignatures", "currentPath", "name", "toString", "isTupleType", "i", "element", "elements", "entries", "isUnion", "types", "isRefinement", "from", "findNode", "child", "_", "isOption", "findProperty", "schema", "getProp", "rest", "typeNode", "invariant", "length", "ast", "split", "defaultAnnotations", "objectKeyword", "stringKeyword", "numberKeyword", "booleanKeyword", "getAnnotation", "annotationId", "noDefault", "id", "pipe", "getIdentifierAnnotation", "Option", "getOrUndefined", "value", "_tag", "annotations", "findAnnotation", "getAnnotationById", "getBaseAnnotation", "isUndefinedKeyword", "isLiteralUnion", "every", "getDiscriminatingProps", "reduce", "shared", "props", "filter", "p", "map", "includes", "getDiscriminatedType", "match", "literal", "fields", "Object", "fromEntries", "literals", "find", "isNonNullable", "S", "Literal", "Struct", "mapAst", "f", "TypeLiteral", "propertySignatures", "PropertySignature", "isOptional", "isReadonly", "indexSignatures", "Union", "make", "TupleType", "t", "index", "OptionalType", "Type", "newAst", "Suspend", "PATH_REGEX", "PROP_REGEX", "JsonPath", "String", "pattern", "JsonProp", "NonEmptyString", "isJsonPath", "isSome", "validateOption", "createJsonPath", "candidatePath", "join", "fromEffectValidationPath", "effectPath", "jsonPath", "replace", "splitJsonPath", "part", "startsWith", "getField", "object", "JSONPath", "json", "ParamKeyAnnotationId", "Symbol", "for", "getParamKeyAnnotation", "ParamKeyAnnotation", "self", "UrlParser", "constructor", "_schema", "parse", "_url", "url", "URL", "params", "key", "searchParams", "get", "decamelize", "parseInt", "create", "forEach", "field", "serializedKey", "getOrElse", "set"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"packages/common/effect/src/ast.ts":{"bytes":40604,"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/effect/src/jsonPath.ts":{"bytes":8452,"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect/Option","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true}],"format":"esm"},"packages/common/effect/src/url.ts":{"bytes":7711,"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/effect/src/index.ts":{"bytes":1238,"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"packages/common/effect/src/ast.ts","kind":"import-statement","original":"./ast"},{"path":"packages/common/effect/src/jsonPath.ts","kind":"import-statement","original":"./jsonPath"},{"path":"packages/common/effect/src/url.ts","kind":"import-statement","original":"./url"}],"format":"esm"}},"outputs":{"packages/common/effect/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":29103},"packages/common/effect/dist/lib/node/index.cjs":{"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect/Option","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["AST","JSONSchema","JsonPath","JsonProp","ParamKeyAnnotation","S","SimpleType","UrlParser","VisitResult","createJsonPath","findAnnotation","findNode","findProperty","fromEffectValidationPath","getAnnotation","getDiscriminatedType","getDiscriminatingProps","getParamKeyAnnotation","getSimpleType","isDiscriminatedUnion","isJsonPath","isLiteralUnion","isOption","isSimpleType","mapAst","splitJsonPath","visit"],"entryPoint":"packages/common/effect/src/index.ts","inputs":{"packages/common/effect/src/index.ts":{"bytesInOutput":72},"packages/common/effect/src/ast.ts":{"bytesInOutput":8515},"packages/common/effect/src/jsonPath.ts":{"bytesInOutput":1558},"packages/common/effect/src/url.ts":{"bytesInOutput":1624}},"bytes":12422}}}
1
+ {"inputs":{"packages/common/effect/src/ast.ts":{"bytes":40556,"imports":[{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/effect/src/jsonPath.ts":{"bytes":9309,"imports":[{"path":"effect","kind":"import-statement","external":true},{"path":"effect/Option","kind":"import-statement","external":true},{"path":"jsonpath-plus","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true}],"format":"esm"},"packages/common/effect/src/url.ts":{"bytes":7659,"imports":[{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/effect/src/index.ts":{"bytes":648,"imports":[{"path":"packages/common/effect/src/ast.ts","kind":"import-statement","original":"./ast"},{"path":"packages/common/effect/src/jsonPath.ts","kind":"import-statement","original":"./jsonPath"},{"path":"packages/common/effect/src/url.ts","kind":"import-statement","original":"./url"}],"format":"esm"}},"outputs":{"packages/common/effect/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":29071},"packages/common/effect/dist/lib/node/index.cjs":{"imports":[{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"effect/Option","kind":"import-statement","external":true},{"path":"jsonpath-plus","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["JsonPath","JsonProp","ParamKeyAnnotation","SimpleType","UrlParser","VisitResult","createJsonPath","findAnnotation","findNode","findProperty","fromEffectValidationPath","getAnnotation","getDiscriminatedType","getDiscriminatingProps","getField","getParamKeyAnnotation","getSimpleType","isDiscriminatedUnion","isJsonPath","isLiteralUnion","isOption","isSimpleType","mapAst","splitJsonPath","visit"],"entryPoint":"packages/common/effect/src/index.ts","inputs":{"packages/common/effect/src/ast.ts":{"bytesInOutput":8495},"packages/common/effect/src/index.ts":{"bytesInOutput":0},"packages/common/effect/src/jsonPath.ts":{"bytesInOutput":1686},"packages/common/effect/src/url.ts":{"bytesInOutput":1597}},"bytes":12363}}}