@dxos/effect 0.8.3-main.672df60 → 0.8.3-staging.0fa589b

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.
@@ -307,12 +307,14 @@ import { JSONPath } from "jsonpath-plus";
307
307
  import { invariant as invariant2 } from "@dxos/invariant";
308
308
  var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/common/effect/src/jsonPath.ts";
309
309
  var PATH_REGEX = /^($|[a-zA-Z_$][\w$]*(?:\.[a-zA-Z_$][\w$]*|\[\d+\](?:\.)?)*$)/;
310
- var PROP_REGEX = /\w+/;
310
+ var PROP_REGEX = /^\w+$/;
311
311
  var JsonPath = Schema2.String.pipe(Schema2.pattern(PATH_REGEX)).annotations({
312
312
  title: "JSON path",
313
313
  description: "JSON path to a property"
314
314
  });
315
- var JsonProp = Schema2.NonEmptyString.pipe(Schema2.pattern(PROP_REGEX));
315
+ var JsonProp = Schema2.NonEmptyString.pipe(Schema2.pattern(PROP_REGEX, {
316
+ message: () => "Property name must contain only letters, numbers, and underscores"
317
+ }));
316
318
  var isJsonPath = (value) => {
317
319
  return Option2.isSome(Schema2.validateOption(JsonPath)(value));
318
320
  };
@@ -326,7 +328,7 @@ var createJsonPath = (path) => {
326
328
  }).join("");
327
329
  invariant2(isJsonPath(candidatePath), `Invalid JsonPath: ${candidatePath}`, {
328
330
  F: __dxlog_file2,
329
- L: 59,
331
+ L: 63,
330
332
  S: void 0,
331
333
  A: [
332
334
  "isJsonPath(candidatePath)",
@@ -339,7 +341,7 @@ var fromEffectValidationPath = (effectPath) => {
339
341
  const jsonPath = effectPath.replace(/\.\[(\d+)\]/g, "[$1]");
340
342
  invariant2(isJsonPath(jsonPath), `Invalid JsonPath: ${jsonPath}`, {
341
343
  F: __dxlog_file2,
342
- L: 70,
344
+ L: 74,
343
345
  S: void 0,
344
346
  A: [
345
347
  "isJsonPath(jsonPath)",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/ast.ts", "../../../src/jsonPath.ts", "../../../src/url.ts"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { Option, pipe, SchemaAST, Schema } 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/SchemaAST.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: SchemaAST.AST): SimpleType | undefined => {\n if (\n SchemaAST.isDeclaration(node) ||\n SchemaAST.isObjectKeyword(node) ||\n SchemaAST.isTypeLiteral(node) ||\n isDiscriminatedUnion(node)\n ) {\n return 'object';\n }\n\n if (SchemaAST.isStringKeyword(node)) {\n return 'string';\n }\n if (SchemaAST.isNumberKeyword(node)) {\n return 'number';\n }\n if (SchemaAST.isBooleanKeyword(node)) {\n return 'boolean';\n }\n\n if (SchemaAST.isEnums(node)) {\n return 'enum';\n }\n\n if (SchemaAST.isLiteral(node)) {\n return 'literal';\n }\n};\n\nexport const isSimpleType = (node: SchemaAST.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: SchemaAST.AST, path: Path, depth: number) => VisitResult | boolean | undefined;\n\nexport type VisitorFn = (node: SchemaAST.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: SchemaAST.AST, visitor: VisitorFn): void;\n (node: SchemaAST.AST, test: TestFn, visitor: VisitorFn): void;\n} = (node: SchemaAST.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: SchemaAST.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 (SchemaAST.isTypeLiteral(node)) {\n for (const prop of SchemaAST.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 (SchemaAST.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 (SchemaAST.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 (SchemaAST.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: SchemaAST.AST, test: (node: SchemaAST.AST) => boolean): SchemaAST.AST | undefined => {\n if (test(node)) {\n return node;\n }\n\n // Object.\n else if (SchemaAST.isTypeLiteral(node)) {\n for (const prop of SchemaAST.getPropertySignatures(node)) {\n const child = findNode(prop.type, test);\n if (child) {\n return child;\n }\n }\n }\n\n // Tuple.\n else if (SchemaAST.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 (SchemaAST.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 (SchemaAST.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 = (\n schema: Schema.Schema.AnyNoContext,\n path: JsonPath | JsonProp,\n): SchemaAST.AST | undefined => {\n const getProp = (node: SchemaAST.AST, path: JsonProp[]): SchemaAST.AST | undefined => {\n const [name, ...rest] = path;\n const typeNode = findNode(node, SchemaAST.isTypeLiteral);\n invariant(typeNode);\n for (const prop of SchemaAST.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, SchemaAST.Annotated> = {\n ['ObjectKeyword' as const]: SchemaAST.objectKeyword,\n ['StringKeyword' as const]: SchemaAST.stringKeyword,\n ['NumberKeyword' as const]: SchemaAST.numberKeyword,\n ['BooleanKeyword' as const]: SchemaAST.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: SchemaAST.AST): T | undefined => {\n // Title fallback seems to be the identifier.\n const id = pipe(SchemaAST.getIdentifierAnnotation(node), Option.getOrUndefined);\n const value = pipe(SchemaAST.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: SchemaAST.AST, annotationId: symbol, noDefault = true): T | undefined => {\n const getAnnotationById = getAnnotation(annotationId, noDefault);\n\n const getBaseAnnotation = (node: SchemaAST.AST): T | undefined => {\n const value = getAnnotationById(node);\n if (value !== undefined) {\n return value as T;\n }\n\n if (SchemaAST.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 Schema.optional creates a union type with undefined as the second type.\n */\nexport const isOption = (node: SchemaAST.AST): boolean => {\n return SchemaAST.isUnion(node) && node.types.length === 2 && SchemaAST.isUndefinedKeyword(node.types[1]);\n};\n\n/**\n * Determines if the node is a union of literal types.\n */\nexport const isLiteralUnion = (node: SchemaAST.AST): boolean => {\n return SchemaAST.isUnion(node) && node.types.every(SchemaAST.isLiteral);\n};\n\n/**\n * Determines if the node is a discriminated union.\n */\nexport const isDiscriminatedUnion = (node: SchemaAST.AST): boolean => {\n return SchemaAST.isUnion(node) && !!getDiscriminatingProps(node)?.length;\n};\n\n/**\n * Get the discriminating properties for the given union type.\n */\nexport const getDiscriminatingProps = (node: SchemaAST.AST): string[] | undefined => {\n invariant(SchemaAST.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 = SchemaAST.getPropertySignatures(type)\n // TODO(burdon): Should check each literal is unique.\n .filter((p) => SchemaAST.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 = (\n node: SchemaAST.AST,\n value: Record<string, any> = {},\n): SchemaAST.AST | undefined => {\n invariant(SchemaAST.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 = SchemaAST.getPropertySignatures(type)\n .filter((prop) => props?.includes(prop.name.toString()))\n .every((prop) => {\n invariant(SchemaAST.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 = SchemaAST.getPropertySignatures(type).find((p) => p.name.toString() === prop)!;\n invariant(SchemaAST.isLiteral(literal.type));\n return literal.type.literal;\n })\n .filter(isNonNullable);\n\n return literals.length ? [prop, Schema.Literal(...literals)] : undefined;\n })\n .filter(isNonNullable),\n );\n\n const schema = Schema.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 SchemaAST.\n * NOTE: Will evaluate suspended ASTs.\n */\nexport const mapAst = (\n ast: SchemaAST.AST,\n f: (ast: SchemaAST.AST, key: keyof any | undefined) => SchemaAST.AST,\n): SchemaAST.AST => {\n switch (ast._tag) {\n case 'TypeLiteral': {\n return new SchemaAST.TypeLiteral(\n ast.propertySignatures.map(\n (prop) =>\n new SchemaAST.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 }\n case 'Union': {\n return SchemaAST.Union.make(ast.types.map(f), ast.annotations);\n }\n case 'TupleType': {\n return new SchemaAST.TupleType(\n ast.elements.map((t, index) => new SchemaAST.OptionalType(f(t.type, index), t.isOptional, t.annotations)),\n ast.rest.map((t) => new SchemaAST.Type(f(t.type, undefined), t.annotations)),\n ast.isReadonly,\n ast.annotations,\n );\n }\n case 'Suspend': {\n const newAst = f(ast.f(), undefined);\n return new SchemaAST.Suspend(() => newAst, ast.annotations);\n }\n default: {\n // TODO(dmaretskyi): Support more nodes.\n return ast;\n }\n }\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Schema, Option } from 'effect';\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 = Schema.String.pipe(Schema.pattern(PATH_REGEX)).annotations({\n title: 'JSON path',\n description: 'JSON path to a property',\n}) as any as Schema.Schema<JsonPath>;\nexport const JsonProp = Schema.NonEmptyString.pipe(Schema.pattern(PROP_REGEX)) as any as Schema.Schema<JsonProp>;\n\nexport const isJsonPath = (value: unknown): value is JsonPath => {\n return Option.isSome(Schema.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, type Schema, 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: SchemaAST.Annotated) => Option.Option<ParamKeyAnnotationValue> =\n SchemaAST.getAnnotation<ParamKeyAnnotationValue>(ParamKeyAnnotationId);\n\nexport const ParamKeyAnnotation =\n (value: ParamKeyAnnotationValue) =>\n <S extends Schema.Annotable.All>(self: S): Schema.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: Schema.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 (SchemaAST.isNumberKeyword(type.ast)) {\n params[key] = parseInt(value);\n } else if (SchemaAST.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,SAASA,QAAQC,MAAMC,WAAWC,cAAc;AAEhD,SAASC,iBAAiB;AAC1B,SAASC,qBAAqB;;AAgBvB,IAAMC,gBAAgB,CAACC,SAAAA;AAC5B,MACEL,UAAUM,cAAcD,IAAAA,KACxBL,UAAUO,gBAAgBF,IAAAA,KAC1BL,UAAUQ,cAAcH,IAAAA,KACxBI,qBAAqBJ,IAAAA,GACrB;AACA,WAAO;EACT;AAEA,MAAIL,UAAUU,gBAAg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C,GAAAA,IAAOd;QAChB;MACF;AAEA,aAAOa;IACT,GAAG,CAAC,CAAA;EACN;;;;EAKAU,OAAOjB,MAAcO,QAAgB;AACnC,UAAMN,MAAM,IAAIC,IAAIF,IAAAA;AACpBG,WAAOC,QAAQG,MAAAA,EAAQW,QAAQ,CAAC,CAACV,KAAKd,KAAAA,MAAM;AAC1C,UAAIA,UAAUyB,QAAW;AACvB,cAAMC,QAAQ,KAAKtB,QAAQO,OAAOG,GAAAA;AAClC,YAAIY,OAAO;AACT,gBAAM,EAAEZ,KAAKa,cAAa,IAAKC,MAC7BhC,sBAAsB8B,MAAMN,GAAG,GAC/BS,QAAOC,UAAU,OAAO;YACtBhB,KAAKI,WAAWJ,GAAAA;UAClB,EAAA,CAAA;AAGFP,cAAIS,aAAae,IAAIJ,eAAeK,OAAOhC,KAAAA,CAAAA;QAC7C;MACF;IACF,CAAA;AAEA,WAAOO;EACT;AACF;",
6
- "names": ["Option", "pipe", "SchemaAST", "Schema", "invariant", "isNonNullable", "getSimpleType", "node", "isDeclaration", "isObjectKeyword", "isTypeLiteral", "isDiscriminatedUnion", "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", "length", "ast", "split", "defaultAnnotations", "objectKeyword", "stringKeyword", "numberKeyword", "booleanKeyword", "getAnnotation", "annotationId", "noDefault", "id", "getIdentifierAnnotation", "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", "Literal", "Struct", "mapAst", "f", "TypeLiteral", "propertySignatures", "PropertySignature", "isOptional", "isReadonly", "indexSignatures", "Union", "make", "TupleType", "t", "index", "OptionalType", "Type", "newAst", "Suspend", "Schema", "Option", "JSONPath", "invariant", "PATH_REGEX", "PROP_REGEX", "JsonPath", "String", "pipe", "pattern", "annotations", "title", "description", "JsonProp", "NonEmptyString", "isJsonPath", "value", "isSome", "validateOption", "createJsonPath", "path", "candidatePath", "map", "p", "i", "join", "fromEffectValidationPath", "effectPath", "jsonPath", "replace", "splitJsonPath", "match", "part", "startsWith", "getField", "object", "json", "SchemaAST", "Option", "pipe", "decamelize", "ParamKeyAnnotationId", "Symbol", "for", "getParamKeyAnnotation", "SchemaAST", "getAnnotation", "ParamKeyAnnotation", "value", "self", "annotations", "UrlParser", "_schema", "parse", "_url", "url", "URL", "Object", "entries", "fields", "reduce", "params", "key", "type", "searchParams", "get", "decamelize", "isNumberKeyword", "ast", "parseInt", "isBooleanKeyword", "create", "forEach", "undefined", "field", "serializedKey", "pipe", "Option", "getOrElse", "set", "String"]
4
+ "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { Option, pipe, SchemaAST, Schema } 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/SchemaAST.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: SchemaAST.AST): SimpleType | undefined => {\n if (\n SchemaAST.isDeclaration(node) ||\n SchemaAST.isObjectKeyword(node) ||\n SchemaAST.isTypeLiteral(node) ||\n isDiscriminatedUnion(node)\n ) {\n return 'object';\n }\n\n if (SchemaAST.isStringKeyword(node)) {\n return 'string';\n }\n if (SchemaAST.isNumberKeyword(node)) {\n return 'number';\n }\n if (SchemaAST.isBooleanKeyword(node)) {\n return 'boolean';\n }\n\n if (SchemaAST.isEnums(node)) {\n return 'enum';\n }\n\n if (SchemaAST.isLiteral(node)) {\n return 'literal';\n }\n};\n\nexport const isSimpleType = (node: SchemaAST.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: SchemaAST.AST, path: Path, depth: number) => VisitResult | boolean | undefined;\n\nexport type VisitorFn = (node: SchemaAST.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: SchemaAST.AST, visitor: VisitorFn): void;\n (node: SchemaAST.AST, test: TestFn, visitor: VisitorFn): void;\n} = (node: SchemaAST.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: SchemaAST.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 (SchemaAST.isTypeLiteral(node)) {\n for (const prop of SchemaAST.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 (SchemaAST.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 (SchemaAST.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 (SchemaAST.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: SchemaAST.AST, test: (node: SchemaAST.AST) => boolean): SchemaAST.AST | undefined => {\n if (test(node)) {\n return node;\n }\n\n // Object.\n else if (SchemaAST.isTypeLiteral(node)) {\n for (const prop of SchemaAST.getPropertySignatures(node)) {\n const child = findNode(prop.type, test);\n if (child) {\n return child;\n }\n }\n }\n\n // Tuple.\n else if (SchemaAST.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 (SchemaAST.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 (SchemaAST.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 = (\n schema: Schema.Schema.AnyNoContext,\n path: JsonPath | JsonProp,\n): SchemaAST.AST | undefined => {\n const getProp = (node: SchemaAST.AST, path: JsonProp[]): SchemaAST.AST | undefined => {\n const [name, ...rest] = path;\n const typeNode = findNode(node, SchemaAST.isTypeLiteral);\n invariant(typeNode);\n for (const prop of SchemaAST.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, SchemaAST.Annotated> = {\n ['ObjectKeyword' as const]: SchemaAST.objectKeyword,\n ['StringKeyword' as const]: SchemaAST.stringKeyword,\n ['NumberKeyword' as const]: SchemaAST.numberKeyword,\n ['BooleanKeyword' as const]: SchemaAST.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: SchemaAST.AST): T | undefined => {\n // Title fallback seems to be the identifier.\n const id = pipe(SchemaAST.getIdentifierAnnotation(node), Option.getOrUndefined);\n const value = pipe(SchemaAST.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: SchemaAST.AST, annotationId: symbol, noDefault = true): T | undefined => {\n const getAnnotationById = getAnnotation(annotationId, noDefault);\n\n const getBaseAnnotation = (node: SchemaAST.AST): T | undefined => {\n const value = getAnnotationById(node);\n if (value !== undefined) {\n return value as T;\n }\n\n if (SchemaAST.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 Schema.optional creates a union type with undefined as the second type.\n */\nexport const isOption = (node: SchemaAST.AST): boolean => {\n return SchemaAST.isUnion(node) && node.types.length === 2 && SchemaAST.isUndefinedKeyword(node.types[1]);\n};\n\n/**\n * Determines if the node is a union of literal types.\n */\nexport const isLiteralUnion = (node: SchemaAST.AST): boolean => {\n return SchemaAST.isUnion(node) && node.types.every(SchemaAST.isLiteral);\n};\n\n/**\n * Determines if the node is a discriminated union.\n */\nexport const isDiscriminatedUnion = (node: SchemaAST.AST): boolean => {\n return SchemaAST.isUnion(node) && !!getDiscriminatingProps(node)?.length;\n};\n\n/**\n * Get the discriminating properties for the given union type.\n */\nexport const getDiscriminatingProps = (node: SchemaAST.AST): string[] | undefined => {\n invariant(SchemaAST.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 = SchemaAST.getPropertySignatures(type)\n // TODO(burdon): Should check each literal is unique.\n .filter((p) => SchemaAST.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 = (\n node: SchemaAST.AST,\n value: Record<string, any> = {},\n): SchemaAST.AST | undefined => {\n invariant(SchemaAST.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 = SchemaAST.getPropertySignatures(type)\n .filter((prop) => props?.includes(prop.name.toString()))\n .every((prop) => {\n invariant(SchemaAST.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 = SchemaAST.getPropertySignatures(type).find((p) => p.name.toString() === prop)!;\n invariant(SchemaAST.isLiteral(literal.type));\n return literal.type.literal;\n })\n .filter(isNonNullable);\n\n return literals.length ? [prop, Schema.Literal(...literals)] : undefined;\n })\n .filter(isNonNullable),\n );\n\n const schema = Schema.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 SchemaAST.\n * NOTE: Will evaluate suspended ASTs.\n */\nexport const mapAst = (\n ast: SchemaAST.AST,\n f: (ast: SchemaAST.AST, key: keyof any | undefined) => SchemaAST.AST,\n): SchemaAST.AST => {\n switch (ast._tag) {\n case 'TypeLiteral': {\n return new SchemaAST.TypeLiteral(\n ast.propertySignatures.map(\n (prop) =>\n new SchemaAST.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 }\n case 'Union': {\n return SchemaAST.Union.make(ast.types.map(f), ast.annotations);\n }\n case 'TupleType': {\n return new SchemaAST.TupleType(\n ast.elements.map((t, index) => new SchemaAST.OptionalType(f(t.type, index), t.isOptional, t.annotations)),\n ast.rest.map((t) => new SchemaAST.Type(f(t.type, undefined), t.annotations)),\n ast.isReadonly,\n ast.annotations,\n );\n }\n case 'Suspend': {\n const newAst = f(ast.f(), undefined);\n return new SchemaAST.Suspend(() => newAst, ast.annotations);\n }\n default: {\n // TODO(dmaretskyi): Support more nodes.\n return ast;\n }\n }\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Schema, Option } from 'effect';\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 = Schema.String.pipe(Schema.pattern(PATH_REGEX)).annotations({\n title: 'JSON path',\n description: 'JSON path to a property',\n}) as any as Schema.Schema<JsonPath>;\nexport const JsonProp = Schema.NonEmptyString.pipe(\n Schema.pattern(PROP_REGEX, {\n message: () => 'Property name must contain only letters, numbers, and underscores',\n }),\n) as any as Schema.Schema<JsonProp>;\n\nexport const isJsonPath = (value: unknown): value is JsonPath => {\n return Option.isSome(Schema.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, type Schema, 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: SchemaAST.Annotated) => Option.Option<ParamKeyAnnotationValue> =\n SchemaAST.getAnnotation<ParamKeyAnnotationValue>(ParamKeyAnnotationId);\n\nexport const ParamKeyAnnotation =\n (value: ParamKeyAnnotationValue) =>\n <S extends Schema.Annotable.All>(self: S): Schema.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: Schema.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 (SchemaAST.isNumberKeyword(type.ast)) {\n params[key] = parseInt(value);\n } else if (SchemaAST.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,SAASA,QAAQC,MAAMC,WAAWC,cAAc;AAEhD,SAASC,iBAAiB;AAC1B,SAASC,qBAAqB;;AAgBvB,IAAMC,gBAAgB,CAACC,SAAAA;AAC5B,MACEL,UAAUM,cAAcD,IAAAA,KACxBL,UAAUO,gBAAgBF,IAAAA,KAC1BL,UAAUQ,cAAcH,IAAAA,KACxBI,qBAAqBJ,IAAAA,GACrB;AACA,WAAO;EACT;AAEA,MAAIL,UAAUU,gBAAgBL,IAAAA,GAAO;AACnC,WAAO;EACT;AACA,MAAIL,UAAUW,gBAAgBN,IAAAA,GAAO;AACnC,WAAO;EACT;AACA,MAAIL,UAAUY,iBAAiBP,IAAAA,GAAO;AACpC,WAAO;EACT;AAEA,MAAIL,UAAUa,QAAQR,IAAAA,GAAO;AAC3B,WAAO;EACT;AAEA,MAAIL,UAAUc,UAAUT,IAAAA,GAAO;AAC7B,WAAO;EACT;AACF;AAEO,IAAMU,eAAe,CAACV,SAAiC,CAAC,CAACD,cAAcC,IAAAA;UAE7DW,aAAAA;cAKFC,kBAAkB,CAACC,SAAAA;AAC9B,YAAQA,MAAAA;MACN,KAAK,UAAU;AACb,eAAO;MACT;MACA,KAAK,UAAU;AACb,eAAO;MACT;MACA,KAAK,WAAW;AACd,eAAO;MACT;MACA,KAAK,UAAU;AACb,eAAO,CAAC;MACV;MACA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hC,KAAAA,CAAAA;QAC7C;MACF;IACF,CAAA;AAEA,WAAOO;EACT;AACF;",
6
+ "names": ["Option", "pipe", "SchemaAST", "Schema", "invariant", "isNonNullable", "getSimpleType", "node", "isDeclaration", "isObjectKeyword", "isTypeLiteral", "isDiscriminatedUnion", "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", "length", "ast", "split", "defaultAnnotations", "objectKeyword", "stringKeyword", "numberKeyword", "booleanKeyword", "getAnnotation", "annotationId", "noDefault", "id", "getIdentifierAnnotation", "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", "Literal", "Struct", "mapAst", "f", "TypeLiteral", "propertySignatures", "PropertySignature", "isOptional", "isReadonly", "indexSignatures", "Union", "make", "TupleType", "t", "index", "OptionalType", "Type", "newAst", "Suspend", "Schema", "Option", "JSONPath", "invariant", "PATH_REGEX", "PROP_REGEX", "JsonPath", "String", "pipe", "pattern", "annotations", "title", "description", "JsonProp", "NonEmptyString", "message", "isJsonPath", "value", "isSome", "validateOption", "createJsonPath", "path", "candidatePath", "map", "p", "i", "join", "fromEffectValidationPath", "effectPath", "jsonPath", "replace", "splitJsonPath", "match", "part", "startsWith", "getField", "object", "json", "SchemaAST", "Option", "pipe", "decamelize", "ParamKeyAnnotationId", "Symbol", "for", "getParamKeyAnnotation", "SchemaAST", "getAnnotation", "ParamKeyAnnotation", "value", "self", "annotations", "UrlParser", "_schema", "parse", "_url", "url", "URL", "Object", "entries", "fields", "reduce", "params", "key", "type", "searchParams", "get", "decamelize", "isNumberKeyword", "ast", "parseInt", "isBooleanKeyword", "create", "forEach", "undefined", "field", "serializedKey", "pipe", "Option", "getOrElse", "set", "String"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"packages/common/effect/src/ast.ts":{"bytes":41244,"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":9448,"imports":[{"path":"effect","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":7566,"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":616,"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/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":29833},"packages/common/effect/dist/lib/browser/index.mjs":{"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":"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":8838},"packages/common/effect/src/index.ts":{"bytesInOutput":0},"packages/common/effect/src/jsonPath.ts":{"bytesInOutput":1783},"packages/common/effect/src/url.ts":{"bytesInOutput":1621}},"bytes":12861}}}
1
+ {"inputs":{"packages/common/effect/src/ast.ts":{"bytes":41244,"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":9732,"imports":[{"path":"effect","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":7566,"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":616,"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/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":29977},"packages/common/effect/dist/lib/browser/index.mjs":{"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":"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":8838},"packages/common/effect/src/index.ts":{"bytesInOutput":0},"packages/common/effect/src/jsonPath.ts":{"bytesInOutput":1875},"packages/common/effect/src/url.ts":{"bytesInOutput":1621}},"bytes":12953}}}
@@ -351,12 +351,14 @@ var mapAst = (ast, f) => {
351
351
  var SimpleType;
352
352
  var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/common/effect/src/jsonPath.ts";
353
353
  var PATH_REGEX = /^($|[a-zA-Z_$][\w$]*(?:\.[a-zA-Z_$][\w$]*|\[\d+\](?:\.)?)*$)/;
354
- var PROP_REGEX = /\w+/;
354
+ var PROP_REGEX = /^\w+$/;
355
355
  var JsonPath = import_effect2.Schema.String.pipe(import_effect2.Schema.pattern(PATH_REGEX)).annotations({
356
356
  title: "JSON path",
357
357
  description: "JSON path to a property"
358
358
  });
359
- var JsonProp = import_effect2.Schema.NonEmptyString.pipe(import_effect2.Schema.pattern(PROP_REGEX));
359
+ var JsonProp = import_effect2.Schema.NonEmptyString.pipe(import_effect2.Schema.pattern(PROP_REGEX, {
360
+ message: () => "Property name must contain only letters, numbers, and underscores"
361
+ }));
360
362
  var isJsonPath = (value) => {
361
363
  return import_effect2.Option.isSome(import_effect2.Schema.validateOption(JsonPath)(value));
362
364
  };
@@ -370,7 +372,7 @@ var createJsonPath = (path) => {
370
372
  }).join("");
371
373
  (0, import_invariant2.invariant)(isJsonPath(candidatePath), `Invalid JsonPath: ${candidatePath}`, {
372
374
  F: __dxlog_file2,
373
- L: 59,
375
+ L: 63,
374
376
  S: void 0,
375
377
  A: [
376
378
  "isJsonPath(candidatePath)",
@@ -383,7 +385,7 @@ var fromEffectValidationPath = (effectPath) => {
383
385
  const jsonPath = effectPath.replace(/\.\[(\d+)\]/g, "[$1]");
384
386
  (0, import_invariant2.invariant)(isJsonPath(jsonPath), `Invalid JsonPath: ${jsonPath}`, {
385
387
  F: __dxlog_file2,
386
- L: 70,
388
+ L: 74,
387
389
  S: void 0,
388
390
  A: [
389
391
  "isJsonPath(jsonPath)",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/ast.ts", "../../../src/jsonPath.ts", "../../../src/url.ts"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { Option, pipe, SchemaAST, Schema } 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/SchemaAST.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: SchemaAST.AST): SimpleType | undefined => {\n if (\n SchemaAST.isDeclaration(node) ||\n SchemaAST.isObjectKeyword(node) ||\n SchemaAST.isTypeLiteral(node) ||\n isDiscriminatedUnion(node)\n ) {\n return 'object';\n }\n\n if (SchemaAST.isStringKeyword(node)) {\n return 'string';\n }\n if (SchemaAST.isNumberKeyword(node)) {\n return 'number';\n }\n if (SchemaAST.isBooleanKeyword(node)) {\n return 'boolean';\n }\n\n if (SchemaAST.isEnums(node)) {\n return 'enum';\n }\n\n if (SchemaAST.isLiteral(node)) {\n return 'literal';\n }\n};\n\nexport const isSimpleType = (node: SchemaAST.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: SchemaAST.AST, path: Path, depth: number) => VisitResult | boolean | undefined;\n\nexport type VisitorFn = (node: SchemaAST.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: SchemaAST.AST, visitor: VisitorFn): void;\n (node: SchemaAST.AST, test: TestFn, visitor: VisitorFn): void;\n} = (node: SchemaAST.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: SchemaAST.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 (SchemaAST.isTypeLiteral(node)) {\n for (const prop of SchemaAST.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 (SchemaAST.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 (SchemaAST.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 (SchemaAST.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: SchemaAST.AST, test: (node: SchemaAST.AST) => boolean): SchemaAST.AST | undefined => {\n if (test(node)) {\n return node;\n }\n\n // Object.\n else if (SchemaAST.isTypeLiteral(node)) {\n for (const prop of SchemaAST.getPropertySignatures(node)) {\n const child = findNode(prop.type, test);\n if (child) {\n return child;\n }\n }\n }\n\n // Tuple.\n else if (SchemaAST.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 (SchemaAST.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 (SchemaAST.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 = (\n schema: Schema.Schema.AnyNoContext,\n path: JsonPath | JsonProp,\n): SchemaAST.AST | undefined => {\n const getProp = (node: SchemaAST.AST, path: JsonProp[]): SchemaAST.AST | undefined => {\n const [name, ...rest] = path;\n const typeNode = findNode(node, SchemaAST.isTypeLiteral);\n invariant(typeNode);\n for (const prop of SchemaAST.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, SchemaAST.Annotated> = {\n ['ObjectKeyword' as const]: SchemaAST.objectKeyword,\n ['StringKeyword' as const]: SchemaAST.stringKeyword,\n ['NumberKeyword' as const]: SchemaAST.numberKeyword,\n ['BooleanKeyword' as const]: SchemaAST.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: SchemaAST.AST): T | undefined => {\n // Title fallback seems to be the identifier.\n const id = pipe(SchemaAST.getIdentifierAnnotation(node), Option.getOrUndefined);\n const value = pipe(SchemaAST.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: SchemaAST.AST, annotationId: symbol, noDefault = true): T | undefined => {\n const getAnnotationById = getAnnotation(annotationId, noDefault);\n\n const getBaseAnnotation = (node: SchemaAST.AST): T | undefined => {\n const value = getAnnotationById(node);\n if (value !== undefined) {\n return value as T;\n }\n\n if (SchemaAST.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 Schema.optional creates a union type with undefined as the second type.\n */\nexport const isOption = (node: SchemaAST.AST): boolean => {\n return SchemaAST.isUnion(node) && node.types.length === 2 && SchemaAST.isUndefinedKeyword(node.types[1]);\n};\n\n/**\n * Determines if the node is a union of literal types.\n */\nexport const isLiteralUnion = (node: SchemaAST.AST): boolean => {\n return SchemaAST.isUnion(node) && node.types.every(SchemaAST.isLiteral);\n};\n\n/**\n * Determines if the node is a discriminated union.\n */\nexport const isDiscriminatedUnion = (node: SchemaAST.AST): boolean => {\n return SchemaAST.isUnion(node) && !!getDiscriminatingProps(node)?.length;\n};\n\n/**\n * Get the discriminating properties for the given union type.\n */\nexport const getDiscriminatingProps = (node: SchemaAST.AST): string[] | undefined => {\n invariant(SchemaAST.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 = SchemaAST.getPropertySignatures(type)\n // TODO(burdon): Should check each literal is unique.\n .filter((p) => SchemaAST.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 = (\n node: SchemaAST.AST,\n value: Record<string, any> = {},\n): SchemaAST.AST | undefined => {\n invariant(SchemaAST.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 = SchemaAST.getPropertySignatures(type)\n .filter((prop) => props?.includes(prop.name.toString()))\n .every((prop) => {\n invariant(SchemaAST.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 = SchemaAST.getPropertySignatures(type).find((p) => p.name.toString() === prop)!;\n invariant(SchemaAST.isLiteral(literal.type));\n return literal.type.literal;\n })\n .filter(isNonNullable);\n\n return literals.length ? [prop, Schema.Literal(...literals)] : undefined;\n })\n .filter(isNonNullable),\n );\n\n const schema = Schema.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 SchemaAST.\n * NOTE: Will evaluate suspended ASTs.\n */\nexport const mapAst = (\n ast: SchemaAST.AST,\n f: (ast: SchemaAST.AST, key: keyof any | undefined) => SchemaAST.AST,\n): SchemaAST.AST => {\n switch (ast._tag) {\n case 'TypeLiteral': {\n return new SchemaAST.TypeLiteral(\n ast.propertySignatures.map(\n (prop) =>\n new SchemaAST.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 }\n case 'Union': {\n return SchemaAST.Union.make(ast.types.map(f), ast.annotations);\n }\n case 'TupleType': {\n return new SchemaAST.TupleType(\n ast.elements.map((t, index) => new SchemaAST.OptionalType(f(t.type, index), t.isOptional, t.annotations)),\n ast.rest.map((t) => new SchemaAST.Type(f(t.type, undefined), t.annotations)),\n ast.isReadonly,\n ast.annotations,\n );\n }\n case 'Suspend': {\n const newAst = f(ast.f(), undefined);\n return new SchemaAST.Suspend(() => newAst, ast.annotations);\n }\n default: {\n // TODO(dmaretskyi): Support more nodes.\n return ast;\n }\n }\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Schema, Option } from 'effect';\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 = Schema.String.pipe(Schema.pattern(PATH_REGEX)).annotations({\n title: 'JSON path',\n description: 'JSON path to a property',\n}) as any as Schema.Schema<JsonPath>;\nexport const JsonProp = Schema.NonEmptyString.pipe(Schema.pattern(PROP_REGEX)) as any as Schema.Schema<JsonProp>;\n\nexport const isJsonPath = (value: unknown): value is JsonPath => {\n return Option.isSome(Schema.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, type Schema, 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: SchemaAST.Annotated) => Option.Option<ParamKeyAnnotationValue> =\n SchemaAST.getAnnotation<ParamKeyAnnotationValue>(ParamKeyAnnotationId);\n\nexport const ParamKeyAnnotation =\n (value: ParamKeyAnnotationValue) =>\n <S extends Schema.Annotable.All>(self: S): Schema.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: Schema.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 (SchemaAST.isNumberKeyword(type.ast)) {\n params[key] = parseInt(value);\n } else if (SchemaAST.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.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IAAAA;AACpB,WAAO5D,OAAOpD,QAAQ,KAAK8G,QAAQ3D,MAAM,EAAEV,OAA4B,CAAC0E,QAAQ,CAACC,KAAK3I,IAAAA,MAAK;AACzF,UAAIsD,QAAQkF,IAAII,aAAaC,QAAIC,yBAAWH,GAAAA,CAAAA;AAC5C,UAAIrF,SAAS,MAAM;AACjBA,gBAAQkF,IAAII,aAAaC,IAAIF,GAAAA;MAC/B;AAEA,UAAIrF,SAAS,MAAM;AACjB,YAAInE,eAAAA,UAAUM,gBAAgBO,KAAKuC,GAAG,GAAG;AACvCmG,iBAAOC,GAAAA,IAAOI,SAASzF,KAAAA;QACzB,WAAWnE,eAAAA,UAAUO,iBAAiBM,KAAKuC,GAAG,GAAG;AAC/CmG,iBAAOC,GAAAA,IAAOrF,UAAU,UAAUA,UAAU;QAC9C,OAAO;AACLoF,iBAAOC,GAAAA,IAAOrF;QAChB;MACF;AAEA,aAAOoF;IACT,GAAG,CAAC,CAAA;EACN;;;;EAKAM,OAAOT,MAAcG,QAAgB;AACnC,UAAMF,MAAM,IAAIC,IAAIF,IAAAA;AACpB5D,WAAOpD,QAAQmH,MAAAA,EAAQO,QAAQ,CAAC,CAACN,KAAKrF,KAAAA,MAAM;AAC1C,UAAIA,UAAUzC,QAAW;AACvB,cAAMqI,QAAQ,KAAKb,QAAQ3D,OAAOiE,GAAAA;AAClC,YAAIO,OAAO;AACT,gBAAM,EAAEP,KAAKQ,cAAa,QAAKjG,eAAAA,MAC7B+E,sBAAsBiB,MAAM3G,GAAG,GAC/Ba,eAAAA,OAAOgG,UAAU,OAAO;YACtBT,SAAKG,yBAAWH,GAAAA;UAClB,EAAA,CAAA;AAGFH,cAAII,aAAaS,IAAIF,eAAe5C,OAAOjD,KAAAA,CAAAA;QAC7C;MACF;IACF,CAAA;AAEA,WAAOkF;EACT;AACF;",
6
- "names": ["import_effect", "import_invariant", "import_util", "getSimpleType", "node", "SchemaAST", "isDeclaration", "isObjectKeyword", "isTypeLiteral", "isDiscriminatedUnion", "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", "Schema", "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", "title", "description", "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", "_schema", "parse", "_url", "url", "URL", "params", "key", "searchParams", "get", "decamelize", "parseInt", "create", "forEach", "field", "serializedKey", "getOrElse", "set"]
4
+ "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { Option, pipe, SchemaAST, Schema } 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/SchemaAST.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: SchemaAST.AST): SimpleType | undefined => {\n if (\n SchemaAST.isDeclaration(node) ||\n SchemaAST.isObjectKeyword(node) ||\n SchemaAST.isTypeLiteral(node) ||\n isDiscriminatedUnion(node)\n ) {\n return 'object';\n }\n\n if (SchemaAST.isStringKeyword(node)) {\n return 'string';\n }\n if (SchemaAST.isNumberKeyword(node)) {\n return 'number';\n }\n if (SchemaAST.isBooleanKeyword(node)) {\n return 'boolean';\n }\n\n if (SchemaAST.isEnums(node)) {\n return 'enum';\n }\n\n if (SchemaAST.isLiteral(node)) {\n return 'literal';\n }\n};\n\nexport const isSimpleType = (node: SchemaAST.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: SchemaAST.AST, path: Path, depth: number) => VisitResult | boolean | undefined;\n\nexport type VisitorFn = (node: SchemaAST.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: SchemaAST.AST, visitor: VisitorFn): void;\n (node: SchemaAST.AST, test: TestFn, visitor: VisitorFn): void;\n} = (node: SchemaAST.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: SchemaAST.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 (SchemaAST.isTypeLiteral(node)) {\n for (const prop of SchemaAST.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 (SchemaAST.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 (SchemaAST.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 (SchemaAST.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: SchemaAST.AST, test: (node: SchemaAST.AST) => boolean): SchemaAST.AST | undefined => {\n if (test(node)) {\n return node;\n }\n\n // Object.\n else if (SchemaAST.isTypeLiteral(node)) {\n for (const prop of SchemaAST.getPropertySignatures(node)) {\n const child = findNode(prop.type, test);\n if (child) {\n return child;\n }\n }\n }\n\n // Tuple.\n else if (SchemaAST.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 (SchemaAST.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 (SchemaAST.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 = (\n schema: Schema.Schema.AnyNoContext,\n path: JsonPath | JsonProp,\n): SchemaAST.AST | undefined => {\n const getProp = (node: SchemaAST.AST, path: JsonProp[]): SchemaAST.AST | undefined => {\n const [name, ...rest] = path;\n const typeNode = findNode(node, SchemaAST.isTypeLiteral);\n invariant(typeNode);\n for (const prop of SchemaAST.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, SchemaAST.Annotated> = {\n ['ObjectKeyword' as const]: SchemaAST.objectKeyword,\n ['StringKeyword' as const]: SchemaAST.stringKeyword,\n ['NumberKeyword' as const]: SchemaAST.numberKeyword,\n ['BooleanKeyword' as const]: SchemaAST.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: SchemaAST.AST): T | undefined => {\n // Title fallback seems to be the identifier.\n const id = pipe(SchemaAST.getIdentifierAnnotation(node), Option.getOrUndefined);\n const value = pipe(SchemaAST.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: SchemaAST.AST, annotationId: symbol, noDefault = true): T | undefined => {\n const getAnnotationById = getAnnotation(annotationId, noDefault);\n\n const getBaseAnnotation = (node: SchemaAST.AST): T | undefined => {\n const value = getAnnotationById(node);\n if (value !== undefined) {\n return value as T;\n }\n\n if (SchemaAST.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 Schema.optional creates a union type with undefined as the second type.\n */\nexport const isOption = (node: SchemaAST.AST): boolean => {\n return SchemaAST.isUnion(node) && node.types.length === 2 && SchemaAST.isUndefinedKeyword(node.types[1]);\n};\n\n/**\n * Determines if the node is a union of literal types.\n */\nexport const isLiteralUnion = (node: SchemaAST.AST): boolean => {\n return SchemaAST.isUnion(node) && node.types.every(SchemaAST.isLiteral);\n};\n\n/**\n * Determines if the node is a discriminated union.\n */\nexport const isDiscriminatedUnion = (node: SchemaAST.AST): boolean => {\n return SchemaAST.isUnion(node) && !!getDiscriminatingProps(node)?.length;\n};\n\n/**\n * Get the discriminating properties for the given union type.\n */\nexport const getDiscriminatingProps = (node: SchemaAST.AST): string[] | undefined => {\n invariant(SchemaAST.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 = SchemaAST.getPropertySignatures(type)\n // TODO(burdon): Should check each literal is unique.\n .filter((p) => SchemaAST.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 = (\n node: SchemaAST.AST,\n value: Record<string, any> = {},\n): SchemaAST.AST | undefined => {\n invariant(SchemaAST.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 = SchemaAST.getPropertySignatures(type)\n .filter((prop) => props?.includes(prop.name.toString()))\n .every((prop) => {\n invariant(SchemaAST.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 = SchemaAST.getPropertySignatures(type).find((p) => p.name.toString() === prop)!;\n invariant(SchemaAST.isLiteral(literal.type));\n return literal.type.literal;\n })\n .filter(isNonNullable);\n\n return literals.length ? [prop, Schema.Literal(...literals)] : undefined;\n })\n .filter(isNonNullable),\n );\n\n const schema = Schema.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 SchemaAST.\n * NOTE: Will evaluate suspended ASTs.\n */\nexport const mapAst = (\n ast: SchemaAST.AST,\n f: (ast: SchemaAST.AST, key: keyof any | undefined) => SchemaAST.AST,\n): SchemaAST.AST => {\n switch (ast._tag) {\n case 'TypeLiteral': {\n return new SchemaAST.TypeLiteral(\n ast.propertySignatures.map(\n (prop) =>\n new SchemaAST.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 }\n case 'Union': {\n return SchemaAST.Union.make(ast.types.map(f), ast.annotations);\n }\n case 'TupleType': {\n return new SchemaAST.TupleType(\n ast.elements.map((t, index) => new SchemaAST.OptionalType(f(t.type, index), t.isOptional, t.annotations)),\n ast.rest.map((t) => new SchemaAST.Type(f(t.type, undefined), t.annotations)),\n ast.isReadonly,\n ast.annotations,\n );\n }\n case 'Suspend': {\n const newAst = f(ast.f(), undefined);\n return new SchemaAST.Suspend(() => newAst, ast.annotations);\n }\n default: {\n // TODO(dmaretskyi): Support more nodes.\n return ast;\n }\n }\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Schema, Option } from 'effect';\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 = Schema.String.pipe(Schema.pattern(PATH_REGEX)).annotations({\n title: 'JSON path',\n description: 'JSON path to a property',\n}) as any as Schema.Schema<JsonPath>;\nexport const JsonProp = Schema.NonEmptyString.pipe(\n Schema.pattern(PROP_REGEX, {\n message: () => 'Property name must contain only letters, numbers, and underscores',\n }),\n) as any as Schema.Schema<JsonProp>;\n\nexport const isJsonPath = (value: unknown): value is JsonPath => {\n return Option.isSome(Schema.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, type Schema, 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: SchemaAST.Annotated) => Option.Option<ParamKeyAnnotationValue> =\n SchemaAST.getAnnotation<ParamKeyAnnotationValue>(ParamKeyAnnotationId);\n\nexport const ParamKeyAnnotation =\n (value: ParamKeyAnnotationValue) =>\n <S extends Schema.Annotable.All>(self: S): Schema.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: Schema.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 (SchemaAST.isNumberKeyword(type.ast)) {\n params[key] = parseInt(value);\n } else if (SchemaAST.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,oBAAgD;AAEhD,uBAA0B;AAC1B,kBAA8B;ACH9B,IAAAA,iBAA+B;AAC/B,2BAAyB;AAEzB,IAAAC,oBAA0B;ACH1B,IAAAD,iBAAqD;AAErD,IAAAE,eAA2B;;AFiBpB,IAAMC,gBAAgB,CAACC,SAAAA;AAC5B,MACEC,wBAAUC,cAAcF,IAAAA,KACxBC,wBAAUE,gBAAgBH,IAAAA,KAC1BC,wBAAUG,cAAcJ,IAAAA,KACxBK,qBAAqBL,IAAAA,GACrB;AACA,WAAO;EACT;AAEA,MAAIC,wBAAUK,gBAAgBN,IAAAA,GA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C,GAAAA,IAAOtF,UAAU,UAAUA,UAAU;QAC9C,OAAO;AACLqF,iBAAOC,GAAAA,IAAOtF;QAChB;MACF;AAEA,aAAOqF;IACT,GAAG,CAAC,CAAA;EACN;;;;EAKAM,OAAOT,MAAcG,QAAgB;AACnC,UAAMF,MAAM,IAAIC,IAAIF,IAAAA;AACpB7D,WAAOpD,QAAQoH,MAAAA,EAAQO,QAAQ,CAAC,CAACN,KAAKtF,KAAAA,MAAM;AAC1C,UAAIA,UAAUzC,QAAW;AACvB,cAAMsI,QAAQ,KAAKb,QAAQ5D,OAAOkE,GAAAA;AAClC,YAAIO,OAAO;AACT,gBAAM,EAAEP,KAAKQ,cAAa,QAAKlG,eAAAA,MAC7BgF,sBAAsBiB,MAAM5G,GAAG,GAC/Ba,eAAAA,OAAOiG,UAAU,OAAO;YACtBT,SAAKG,yBAAWH,GAAAA;UAClB,EAAA,CAAA;AAGFH,cAAII,aAAaS,IAAIF,eAAe7C,OAAOjD,KAAAA,CAAAA;QAC7C;MACF;IACF,CAAA;AAEA,WAAOmF;EACT;AACF;",
6
+ "names": ["import_effect", "import_invariant", "import_util", "getSimpleType", "node", "SchemaAST", "isDeclaration", "isObjectKeyword", "isTypeLiteral", "isDiscriminatedUnion", "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", "Schema", "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", "title", "description", "JsonProp", "NonEmptyString", "message", "isJsonPath", "isSome", "validateOption", "createJsonPath", "candidatePath", "join", "fromEffectValidationPath", "effectPath", "jsonPath", "replace", "splitJsonPath", "part", "startsWith", "getField", "object", "JSONPath", "json", "ParamKeyAnnotationId", "Symbol", "for", "getParamKeyAnnotation", "ParamKeyAnnotation", "self", "UrlParser", "_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":41244,"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":9448,"imports":[{"path":"effect","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":7566,"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":616,"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":29831},"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":"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":8838},"packages/common/effect/src/index.ts":{"bytesInOutput":0},"packages/common/effect/src/jsonPath.ts":{"bytesInOutput":1783},"packages/common/effect/src/url.ts":{"bytesInOutput":1621}},"bytes":12827}}}
1
+ {"inputs":{"packages/common/effect/src/ast.ts":{"bytes":41244,"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":9732,"imports":[{"path":"effect","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":7566,"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":616,"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":29975},"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":"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":8838},"packages/common/effect/src/index.ts":{"bytesInOutput":0},"packages/common/effect/src/jsonPath.ts":{"bytesInOutput":1875},"packages/common/effect/src/url.ts":{"bytesInOutput":1621}},"bytes":12919}}}
@@ -307,12 +307,14 @@ import { JSONPath } from "jsonpath-plus";
307
307
  import { invariant as invariant2 } from "@dxos/invariant";
308
308
  var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/common/effect/src/jsonPath.ts";
309
309
  var PATH_REGEX = /^($|[a-zA-Z_$][\w$]*(?:\.[a-zA-Z_$][\w$]*|\[\d+\](?:\.)?)*$)/;
310
- var PROP_REGEX = /\w+/;
310
+ var PROP_REGEX = /^\w+$/;
311
311
  var JsonPath = Schema2.String.pipe(Schema2.pattern(PATH_REGEX)).annotations({
312
312
  title: "JSON path",
313
313
  description: "JSON path to a property"
314
314
  });
315
- var JsonProp = Schema2.NonEmptyString.pipe(Schema2.pattern(PROP_REGEX));
315
+ var JsonProp = Schema2.NonEmptyString.pipe(Schema2.pattern(PROP_REGEX, {
316
+ message: () => "Property name must contain only letters, numbers, and underscores"
317
+ }));
316
318
  var isJsonPath = (value) => {
317
319
  return Option2.isSome(Schema2.validateOption(JsonPath)(value));
318
320
  };
@@ -326,7 +328,7 @@ var createJsonPath = (path) => {
326
328
  }).join("");
327
329
  invariant2(isJsonPath(candidatePath), `Invalid JsonPath: ${candidatePath}`, {
328
330
  F: __dxlog_file2,
329
- L: 59,
331
+ L: 63,
330
332
  S: void 0,
331
333
  A: [
332
334
  "isJsonPath(candidatePath)",
@@ -339,7 +341,7 @@ var fromEffectValidationPath = (effectPath) => {
339
341
  const jsonPath = effectPath.replace(/\.\[(\d+)\]/g, "[$1]");
340
342
  invariant2(isJsonPath(jsonPath), `Invalid JsonPath: ${jsonPath}`, {
341
343
  F: __dxlog_file2,
342
- L: 70,
344
+ L: 74,
343
345
  S: void 0,
344
346
  A: [
345
347
  "isJsonPath(jsonPath)",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/ast.ts", "../../../src/jsonPath.ts", "../../../src/url.ts"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { Option, pipe, SchemaAST, Schema } 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/SchemaAST.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: SchemaAST.AST): SimpleType | undefined => {\n if (\n SchemaAST.isDeclaration(node) ||\n SchemaAST.isObjectKeyword(node) ||\n SchemaAST.isTypeLiteral(node) ||\n isDiscriminatedUnion(node)\n ) {\n return 'object';\n }\n\n if (SchemaAST.isStringKeyword(node)) {\n return 'string';\n }\n if (SchemaAST.isNumberKeyword(node)) {\n return 'number';\n }\n if (SchemaAST.isBooleanKeyword(node)) {\n return 'boolean';\n }\n\n if (SchemaAST.isEnums(node)) {\n return 'enum';\n }\n\n if (SchemaAST.isLiteral(node)) {\n return 'literal';\n }\n};\n\nexport const isSimpleType = (node: SchemaAST.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: SchemaAST.AST, path: Path, depth: number) => VisitResult | boolean | undefined;\n\nexport type VisitorFn = (node: SchemaAST.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: SchemaAST.AST, visitor: VisitorFn): void;\n (node: SchemaAST.AST, test: TestFn, visitor: VisitorFn): void;\n} = (node: SchemaAST.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: SchemaAST.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 (SchemaAST.isTypeLiteral(node)) {\n for (const prop of SchemaAST.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 (SchemaAST.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 (SchemaAST.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 (SchemaAST.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: SchemaAST.AST, test: (node: SchemaAST.AST) => boolean): SchemaAST.AST | undefined => {\n if (test(node)) {\n return node;\n }\n\n // Object.\n else if (SchemaAST.isTypeLiteral(node)) {\n for (const prop of SchemaAST.getPropertySignatures(node)) {\n const child = findNode(prop.type, test);\n if (child) {\n return child;\n }\n }\n }\n\n // Tuple.\n else if (SchemaAST.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 (SchemaAST.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 (SchemaAST.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 = (\n schema: Schema.Schema.AnyNoContext,\n path: JsonPath | JsonProp,\n): SchemaAST.AST | undefined => {\n const getProp = (node: SchemaAST.AST, path: JsonProp[]): SchemaAST.AST | undefined => {\n const [name, ...rest] = path;\n const typeNode = findNode(node, SchemaAST.isTypeLiteral);\n invariant(typeNode);\n for (const prop of SchemaAST.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, SchemaAST.Annotated> = {\n ['ObjectKeyword' as const]: SchemaAST.objectKeyword,\n ['StringKeyword' as const]: SchemaAST.stringKeyword,\n ['NumberKeyword' as const]: SchemaAST.numberKeyword,\n ['BooleanKeyword' as const]: SchemaAST.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: SchemaAST.AST): T | undefined => {\n // Title fallback seems to be the identifier.\n const id = pipe(SchemaAST.getIdentifierAnnotation(node), Option.getOrUndefined);\n const value = pipe(SchemaAST.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: SchemaAST.AST, annotationId: symbol, noDefault = true): T | undefined => {\n const getAnnotationById = getAnnotation(annotationId, noDefault);\n\n const getBaseAnnotation = (node: SchemaAST.AST): T | undefined => {\n const value = getAnnotationById(node);\n if (value !== undefined) {\n return value as T;\n }\n\n if (SchemaAST.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 Schema.optional creates a union type with undefined as the second type.\n */\nexport const isOption = (node: SchemaAST.AST): boolean => {\n return SchemaAST.isUnion(node) && node.types.length === 2 && SchemaAST.isUndefinedKeyword(node.types[1]);\n};\n\n/**\n * Determines if the node is a union of literal types.\n */\nexport const isLiteralUnion = (node: SchemaAST.AST): boolean => {\n return SchemaAST.isUnion(node) && node.types.every(SchemaAST.isLiteral);\n};\n\n/**\n * Determines if the node is a discriminated union.\n */\nexport const isDiscriminatedUnion = (node: SchemaAST.AST): boolean => {\n return SchemaAST.isUnion(node) && !!getDiscriminatingProps(node)?.length;\n};\n\n/**\n * Get the discriminating properties for the given union type.\n */\nexport const getDiscriminatingProps = (node: SchemaAST.AST): string[] | undefined => {\n invariant(SchemaAST.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 = SchemaAST.getPropertySignatures(type)\n // TODO(burdon): Should check each literal is unique.\n .filter((p) => SchemaAST.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 = (\n node: SchemaAST.AST,\n value: Record<string, any> = {},\n): SchemaAST.AST | undefined => {\n invariant(SchemaAST.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 = SchemaAST.getPropertySignatures(type)\n .filter((prop) => props?.includes(prop.name.toString()))\n .every((prop) => {\n invariant(SchemaAST.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 = SchemaAST.getPropertySignatures(type).find((p) => p.name.toString() === prop)!;\n invariant(SchemaAST.isLiteral(literal.type));\n return literal.type.literal;\n })\n .filter(isNonNullable);\n\n return literals.length ? [prop, Schema.Literal(...literals)] : undefined;\n })\n .filter(isNonNullable),\n );\n\n const schema = Schema.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 SchemaAST.\n * NOTE: Will evaluate suspended ASTs.\n */\nexport const mapAst = (\n ast: SchemaAST.AST,\n f: (ast: SchemaAST.AST, key: keyof any | undefined) => SchemaAST.AST,\n): SchemaAST.AST => {\n switch (ast._tag) {\n case 'TypeLiteral': {\n return new SchemaAST.TypeLiteral(\n ast.propertySignatures.map(\n (prop) =>\n new SchemaAST.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 }\n case 'Union': {\n return SchemaAST.Union.make(ast.types.map(f), ast.annotations);\n }\n case 'TupleType': {\n return new SchemaAST.TupleType(\n ast.elements.map((t, index) => new SchemaAST.OptionalType(f(t.type, index), t.isOptional, t.annotations)),\n ast.rest.map((t) => new SchemaAST.Type(f(t.type, undefined), t.annotations)),\n ast.isReadonly,\n ast.annotations,\n );\n }\n case 'Suspend': {\n const newAst = f(ast.f(), undefined);\n return new SchemaAST.Suspend(() => newAst, ast.annotations);\n }\n default: {\n // TODO(dmaretskyi): Support more nodes.\n return ast;\n }\n }\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Schema, Option } from 'effect';\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 = Schema.String.pipe(Schema.pattern(PATH_REGEX)).annotations({\n title: 'JSON path',\n description: 'JSON path to a property',\n}) as any as Schema.Schema<JsonPath>;\nexport const JsonProp = Schema.NonEmptyString.pipe(Schema.pattern(PROP_REGEX)) as any as Schema.Schema<JsonProp>;\n\nexport const isJsonPath = (value: unknown): value is JsonPath => {\n return Option.isSome(Schema.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, type Schema, 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: SchemaAST.Annotated) => Option.Option<ParamKeyAnnotationValue> =\n SchemaAST.getAnnotation<ParamKeyAnnotationValue>(ParamKeyAnnotationId);\n\nexport const ParamKeyAnnotation =\n (value: ParamKeyAnnotationValue) =>\n <S extends Schema.Annotable.All>(self: S): Schema.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: Schema.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 (SchemaAST.isNumberKeyword(type.ast)) {\n params[key] = parseInt(value);\n } else if (SchemaAST.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,SAASA,QAAQC,MAAMC,WAAWC,cAAc;AAEhD,SAASC,iBAAiB;AAC1B,SAASC,qBAAqB;;AAgBvB,IAAMC,gBAAgB,CAACC,SAAAA;AAC5B,MACEL,UAAUM,cAAcD,IAAAA,KACxBL,UAAUO,gBAAgBF,IAAAA,KAC1BL,UAAUQ,cAAcH,IAAAA,KACxBI,qBAAqBJ,IAAAA,GACrB;AACA,WAAO;EACT;AAEA,MAAIL,UAAUU,gBAAgBL,IAAAA,GAAO;AACnC,WAAO;EACT;AACA,MAAIL,UAAUW,gBAAgBN,IAAAA,GAAO;AACnC,WAAO;EACT;AACA,MAAIL,UAAUY,iBAAiBP,IAAAA,GAAO;AACpC,WAAO;EACT;AAEA,MAAIL,UAAUa,QAAQR,IAAAA,GAAO;AAC3B,WAAO;EACT;AAEA,MAAIL,UAAUc,UAAUT,IAAAA,GAAO;AAC7B,WAAO;EACT;AACF;AAEO,IAAMU,eAAe,CAACV,SAAiC,CAAC,CAACD,cAAcC,IAAAA;UAE7DW,aAAAA;cAKFC,kBAAkB,CAACC,SAAAA;AAC9B,YAAQA,MAAAA;MACN,KAAK,UAAU;AACb,eAAO;MACT;MACA,KAAK,UAAU;AACb,eAAO;MACT;MACA,KAAK,WAAW;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S,aAAae,IAAIJ,eAAeK,OAAOhC,KAAAA,CAAAA;QAC7C;MACF;IACF,CAAA;AAEA,WAAOO;EACT;AACF;",
6
- "names": ["Option", "pipe", "SchemaAST", "Schema", "invariant", "isNonNullable", "getSimpleType", "node", "isDeclaration", "isObjectKeyword", "isTypeLiteral", "isDiscriminatedUnion", "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", "length", "ast", "split", "defaultAnnotations", "objectKeyword", "stringKeyword", "numberKeyword", "booleanKeyword", "getAnnotation", "annotationId", "noDefault", "id", "getIdentifierAnnotation", "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", "Literal", "Struct", "mapAst", "f", "TypeLiteral", "propertySignatures", "PropertySignature", "isOptional", "isReadonly", "indexSignatures", "Union", "make", "TupleType", "t", "index", "OptionalType", "Type", "newAst", "Suspend", "Schema", "Option", "JSONPath", "invariant", "PATH_REGEX", "PROP_REGEX", "JsonPath", "String", "pipe", "pattern", "annotations", "title", "description", "JsonProp", "NonEmptyString", "isJsonPath", "value", "isSome", "validateOption", "createJsonPath", "path", "candidatePath", "map", "p", "i", "join", "fromEffectValidationPath", "effectPath", "jsonPath", "replace", "splitJsonPath", "match", "part", "startsWith", "getField", "object", "json", "SchemaAST", "Option", "pipe", "decamelize", "ParamKeyAnnotationId", "Symbol", "for", "getParamKeyAnnotation", "SchemaAST", "getAnnotation", "ParamKeyAnnotation", "value", "self", "annotations", "UrlParser", "_schema", "parse", "_url", "url", "URL", "Object", "entries", "fields", "reduce", "params", "key", "type", "searchParams", "get", "decamelize", "isNumberKeyword", "ast", "parseInt", "isBooleanKeyword", "create", "forEach", "undefined", "field", "serializedKey", "pipe", "Option", "getOrElse", "set", "String"]
4
+ "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { Option, pipe, SchemaAST, Schema } 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/SchemaAST.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: SchemaAST.AST): SimpleType | undefined => {\n if (\n SchemaAST.isDeclaration(node) ||\n SchemaAST.isObjectKeyword(node) ||\n SchemaAST.isTypeLiteral(node) ||\n isDiscriminatedUnion(node)\n ) {\n return 'object';\n }\n\n if (SchemaAST.isStringKeyword(node)) {\n return 'string';\n }\n if (SchemaAST.isNumberKeyword(node)) {\n return 'number';\n }\n if (SchemaAST.isBooleanKeyword(node)) {\n return 'boolean';\n }\n\n if (SchemaAST.isEnums(node)) {\n return 'enum';\n }\n\n if (SchemaAST.isLiteral(node)) {\n return 'literal';\n }\n};\n\nexport const isSimpleType = (node: SchemaAST.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: SchemaAST.AST, path: Path, depth: number) => VisitResult | boolean | undefined;\n\nexport type VisitorFn = (node: SchemaAST.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: SchemaAST.AST, visitor: VisitorFn): void;\n (node: SchemaAST.AST, test: TestFn, visitor: VisitorFn): void;\n} = (node: SchemaAST.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: SchemaAST.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 (SchemaAST.isTypeLiteral(node)) {\n for (const prop of SchemaAST.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 (SchemaAST.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 (SchemaAST.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 (SchemaAST.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: SchemaAST.AST, test: (node: SchemaAST.AST) => boolean): SchemaAST.AST | undefined => {\n if (test(node)) {\n return node;\n }\n\n // Object.\n else if (SchemaAST.isTypeLiteral(node)) {\n for (const prop of SchemaAST.getPropertySignatures(node)) {\n const child = findNode(prop.type, test);\n if (child) {\n return child;\n }\n }\n }\n\n // Tuple.\n else if (SchemaAST.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 (SchemaAST.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 (SchemaAST.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 = (\n schema: Schema.Schema.AnyNoContext,\n path: JsonPath | JsonProp,\n): SchemaAST.AST | undefined => {\n const getProp = (node: SchemaAST.AST, path: JsonProp[]): SchemaAST.AST | undefined => {\n const [name, ...rest] = path;\n const typeNode = findNode(node, SchemaAST.isTypeLiteral);\n invariant(typeNode);\n for (const prop of SchemaAST.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, SchemaAST.Annotated> = {\n ['ObjectKeyword' as const]: SchemaAST.objectKeyword,\n ['StringKeyword' as const]: SchemaAST.stringKeyword,\n ['NumberKeyword' as const]: SchemaAST.numberKeyword,\n ['BooleanKeyword' as const]: SchemaAST.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: SchemaAST.AST): T | undefined => {\n // Title fallback seems to be the identifier.\n const id = pipe(SchemaAST.getIdentifierAnnotation(node), Option.getOrUndefined);\n const value = pipe(SchemaAST.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: SchemaAST.AST, annotationId: symbol, noDefault = true): T | undefined => {\n const getAnnotationById = getAnnotation(annotationId, noDefault);\n\n const getBaseAnnotation = (node: SchemaAST.AST): T | undefined => {\n const value = getAnnotationById(node);\n if (value !== undefined) {\n return value as T;\n }\n\n if (SchemaAST.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 Schema.optional creates a union type with undefined as the second type.\n */\nexport const isOption = (node: SchemaAST.AST): boolean => {\n return SchemaAST.isUnion(node) && node.types.length === 2 && SchemaAST.isUndefinedKeyword(node.types[1]);\n};\n\n/**\n * Determines if the node is a union of literal types.\n */\nexport const isLiteralUnion = (node: SchemaAST.AST): boolean => {\n return SchemaAST.isUnion(node) && node.types.every(SchemaAST.isLiteral);\n};\n\n/**\n * Determines if the node is a discriminated union.\n */\nexport const isDiscriminatedUnion = (node: SchemaAST.AST): boolean => {\n return SchemaAST.isUnion(node) && !!getDiscriminatingProps(node)?.length;\n};\n\n/**\n * Get the discriminating properties for the given union type.\n */\nexport const getDiscriminatingProps = (node: SchemaAST.AST): string[] | undefined => {\n invariant(SchemaAST.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 = SchemaAST.getPropertySignatures(type)\n // TODO(burdon): Should check each literal is unique.\n .filter((p) => SchemaAST.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 = (\n node: SchemaAST.AST,\n value: Record<string, any> = {},\n): SchemaAST.AST | undefined => {\n invariant(SchemaAST.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 = SchemaAST.getPropertySignatures(type)\n .filter((prop) => props?.includes(prop.name.toString()))\n .every((prop) => {\n invariant(SchemaAST.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 = SchemaAST.getPropertySignatures(type).find((p) => p.name.toString() === prop)!;\n invariant(SchemaAST.isLiteral(literal.type));\n return literal.type.literal;\n })\n .filter(isNonNullable);\n\n return literals.length ? [prop, Schema.Literal(...literals)] : undefined;\n })\n .filter(isNonNullable),\n );\n\n const schema = Schema.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 SchemaAST.\n * NOTE: Will evaluate suspended ASTs.\n */\nexport const mapAst = (\n ast: SchemaAST.AST,\n f: (ast: SchemaAST.AST, key: keyof any | undefined) => SchemaAST.AST,\n): SchemaAST.AST => {\n switch (ast._tag) {\n case 'TypeLiteral': {\n return new SchemaAST.TypeLiteral(\n ast.propertySignatures.map(\n (prop) =>\n new SchemaAST.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 }\n case 'Union': {\n return SchemaAST.Union.make(ast.types.map(f), ast.annotations);\n }\n case 'TupleType': {\n return new SchemaAST.TupleType(\n ast.elements.map((t, index) => new SchemaAST.OptionalType(f(t.type, index), t.isOptional, t.annotations)),\n ast.rest.map((t) => new SchemaAST.Type(f(t.type, undefined), t.annotations)),\n ast.isReadonly,\n ast.annotations,\n );\n }\n case 'Suspend': {\n const newAst = f(ast.f(), undefined);\n return new SchemaAST.Suspend(() => newAst, ast.annotations);\n }\n default: {\n // TODO(dmaretskyi): Support more nodes.\n return ast;\n }\n }\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Schema, Option } from 'effect';\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 = Schema.String.pipe(Schema.pattern(PATH_REGEX)).annotations({\n title: 'JSON path',\n description: 'JSON path to a property',\n}) as any as Schema.Schema<JsonPath>;\nexport const JsonProp = Schema.NonEmptyString.pipe(\n Schema.pattern(PROP_REGEX, {\n message: () => 'Property name must contain only letters, numbers, and underscores',\n }),\n) as any as Schema.Schema<JsonProp>;\n\nexport const isJsonPath = (value: unknown): value is JsonPath => {\n return Option.isSome(Schema.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, type Schema, 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: SchemaAST.Annotated) => Option.Option<ParamKeyAnnotationValue> =\n SchemaAST.getAnnotation<ParamKeyAnnotationValue>(ParamKeyAnnotationId);\n\nexport const ParamKeyAnnotation =\n (value: ParamKeyAnnotationValue) =>\n <S extends Schema.Annotable.All>(self: S): Schema.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: Schema.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 (SchemaAST.isNumberKeyword(type.ast)) {\n params[key] = parseInt(value);\n } else if (SchemaAST.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,SAASA,QAAQC,MAAMC,WAAWC,cAAc;AAEhD,SAASC,iBAAiB;AAC1B,SAASC,qBAAq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UAAId,SAAS,MAAM;AACjB,YAAIH,WAAUsB,gBAAgBJ,KAAKK,GAAG,GAAG;AACvCP,iBAAOC,GAAAA,IAAOO,SAASrB,KAAAA;QACzB,WAAWH,WAAUyB,iBAAiBP,KAAKK,GAAG,GAAG;AAC/CP,iBAAOC,GAAAA,IAAOd,UAAU,UAAUA,UAAU;QAC9C,OAAO;AACLa,iBAAOC,GAAAA,IAAOd;QAChB;MACF;AAEA,aAAOa;IACT,GAAG,CAAC,CAAA;EACN;;;;EAKAU,OAAOjB,MAAcO,QAAgB;AACnC,UAAMN,MAAM,IAAIC,IAAIF,IAAAA;AACpBG,WAAOC,QAAQG,MAAAA,EAAQW,QAAQ,CAAC,CAACV,KAAKd,KAAAA,MAAM;AAC1C,UAAIA,UAAUyB,QAAW;AACvB,cAAMC,QAAQ,KAAKtB,QAAQO,OAAOG,GAAAA;AAClC,YAAIY,OAAO;AACT,gBAAM,EAAEZ,KAAKa,cAAa,IAAKC,MAC7BhC,sBAAsB8B,MAAMN,GAAG,GAC/BS,QAAOC,UAAU,OAAO;YACtBhB,KAAKI,WAAWJ,GAAAA;UAClB,EAAA,CAAA;AAGFP,cAAIS,aAAae,IAAIJ,eAAeK,OAAOhC,KAAAA,CAAAA;QAC7C;MACF;IACF,CAAA;AAEA,WAAOO;EACT;AACF;",
6
+ "names": ["Option", "pipe", "SchemaAST", "Schema", "invariant", "isNonNullable", "getSimpleType", "node", "isDeclaration", "isObjectKeyword", "isTypeLiteral", "isDiscriminatedUnion", "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", "length", "ast", "split", "defaultAnnotations", "objectKeyword", "stringKeyword", "numberKeyword", "booleanKeyword", "getAnnotation", "annotationId", "noDefault", "id", "getIdentifierAnnotation", "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", "Literal", "Struct", "mapAst", "f", "TypeLiteral", "propertySignatures", "PropertySignature", "isOptional", "isReadonly", "indexSignatures", "Union", "make", "TupleType", "t", "index", "OptionalType", "Type", "newAst", "Suspend", "Schema", "Option", "JSONPath", "invariant", "PATH_REGEX", "PROP_REGEX", "JsonPath", "String", "pipe", "pattern", "annotations", "title", "description", "JsonProp", "NonEmptyString", "message", "isJsonPath", "value", "isSome", "validateOption", "createJsonPath", "path", "candidatePath", "map", "p", "i", "join", "fromEffectValidationPath", "effectPath", "jsonPath", "replace", "splitJsonPath", "match", "part", "startsWith", "getField", "object", "json", "SchemaAST", "Option", "pipe", "decamelize", "ParamKeyAnnotationId", "Symbol", "for", "getParamKeyAnnotation", "SchemaAST", "getAnnotation", "ParamKeyAnnotation", "value", "self", "annotations", "UrlParser", "_schema", "parse", "_url", "url", "URL", "Object", "entries", "fields", "reduce", "params", "key", "type", "searchParams", "get", "decamelize", "isNumberKeyword", "ast", "parseInt", "isBooleanKeyword", "create", "forEach", "undefined", "field", "serializedKey", "pipe", "Option", "getOrElse", "set", "String"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"packages/common/effect/src/ast.ts":{"bytes":41244,"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":9448,"imports":[{"path":"effect","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":7566,"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":616,"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-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":29833},"packages/common/effect/dist/lib/node-esm/index.mjs":{"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":"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":8838},"packages/common/effect/src/index.ts":{"bytesInOutput":0},"packages/common/effect/src/jsonPath.ts":{"bytesInOutput":1783},"packages/common/effect/src/url.ts":{"bytesInOutput":1621}},"bytes":12920}}}
1
+ {"inputs":{"packages/common/effect/src/ast.ts":{"bytes":41244,"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":9732,"imports":[{"path":"effect","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":7566,"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":616,"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-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":29977},"packages/common/effect/dist/lib/node-esm/index.mjs":{"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":"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":8838},"packages/common/effect/src/index.ts":{"bytesInOutput":0},"packages/common/effect/src/jsonPath.ts":{"bytesInOutput":1875},"packages/common/effect/src/url.ts":{"bytesInOutput":1621}},"bytes":13012}}}
@@ -1 +1 @@
1
- {"version":3,"file":"j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,IAAI,CAAA;CAAE,CAAC;AAKrD;;GAEG;AACH,eAAO,MAAM,QAAQ,EAGR,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AACrC,eAAO,MAAM,QAAQ,EAIT,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AAEpC,eAAO,MAAM,UAAU,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,QAEpD,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,cAAc,GAAI,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,KAAG,QAa1D,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,wBAAwB,GAAI,YAAY,MAAM,KAAG,QAK7D,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,aAAa,GAAI,MAAM,QAAQ,KAAG,MAAM,EAUpD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,QAAQ,GAAI,QAAQ,GAAG,EAAE,MAAM,QAAQ,KAAG,GAGtD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/effect",
3
- "version": "0.8.3-main.672df60",
3
+ "version": "0.8.3-staging.0fa589b",
4
4
  "description": "Effect utils.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -24,13 +24,13 @@
24
24
  ],
25
25
  "dependencies": {
26
26
  "jsonpath-plus": "10.2.0",
27
- "@dxos/invariant": "0.8.3-main.672df60",
28
- "@dxos/node-std": "0.8.3-main.672df60",
29
- "@dxos/util": "0.8.3-main.672df60"
27
+ "@dxos/util": "0.8.3-staging.0fa589b",
28
+ "@dxos/invariant": "0.8.3-staging.0fa589b",
29
+ "@dxos/node-std": "0.8.3-staging.0fa589b"
30
30
  },
31
31
  "devDependencies": {
32
32
  "effect": "3.14.21",
33
- "@dxos/log": "0.8.3-main.672df60"
33
+ "@dxos/log": "0.8.3-staging.0fa589b"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "effect": "^3.13.3"
package/src/jsonPath.ts CHANGED
@@ -11,7 +11,7 @@ export type JsonProp = string & { __JsonPath: true; __JsonProp: true };
11
11
  export type JsonPath = string & { __JsonPath: true };
12
12
 
13
13
  const PATH_REGEX = /^($|[a-zA-Z_$][\w$]*(?:\.[a-zA-Z_$][\w$]*|\[\d+\](?:\.)?)*$)/;
14
- const PROP_REGEX = /\w+/;
14
+ const PROP_REGEX = /^\w+$/;
15
15
 
16
16
  /**
17
17
  * https://www.ietf.org/archive/id/draft-goessner-dispatch-jsonpath-00.html
@@ -20,7 +20,11 @@ export const JsonPath = Schema.String.pipe(Schema.pattern(PATH_REGEX)).annotatio
20
20
  title: 'JSON path',
21
21
  description: 'JSON path to a property',
22
22
  }) as any as Schema.Schema<JsonPath>;
23
- export const JsonProp = Schema.NonEmptyString.pipe(Schema.pattern(PROP_REGEX)) as any as Schema.Schema<JsonProp>;
23
+ export const JsonProp = Schema.NonEmptyString.pipe(
24
+ Schema.pattern(PROP_REGEX, {
25
+ message: () => 'Property name must contain only letters, numbers, and underscores',
26
+ }),
27
+ ) as any as Schema.Schema<JsonProp>;
24
28
 
25
29
  export const isJsonPath = (value: unknown): value is JsonPath => {
26
30
  return Option.isSome(Schema.validateOption(JsonPath)(value));