@dxos/effect 0.7.4 → 0.7.5-feature-compute.4d9d99a

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.
@@ -10,7 +10,7 @@ import { invariant } from "@dxos/invariant";
10
10
  import { nonNullable } from "@dxos/util";
11
11
  var __dxlog_file = "/home/runner/work/dxos/dxos/packages/common/effect/src/ast.ts";
12
12
  var getSimpleType = (node) => {
13
- if (AST.isObjectKeyword(node) || AST.isTypeLiteral(node) || isDiscriminatedUnion(node)) {
13
+ if (AST.isObjectKeyword(node) || AST.isTypeLiteral(node) || isDiscriminatedUnion(node) || AST.isDeclaration(node)) {
14
14
  return "object";
15
15
  }
16
16
  if (AST.isStringKeyword(node)) {
@@ -52,7 +52,7 @@ var SimpleType;
52
52
  }
53
53
  };
54
54
  })(SimpleType || (SimpleType = {}));
55
- var PATH_REGEX = /[a-zA-Z_$][\w$]*(?:\.[a-zA-Z_$][\w$]*)*/;
55
+ var PATH_REGEX = /^[a-zA-Z_$][\w$]*(?:\.[a-zA-Z_$][\w$]*|\[\d+\])*$/;
56
56
  var PROP_REGEX = /\w+/;
57
57
  var JsonPath = S.NonEmptyString.pipe(S.pattern(PATH_REGEX));
58
58
  var JsonProp = S.NonEmptyString.pipe(S.pattern(PROP_REGEX));
@@ -291,13 +291,13 @@ var getDiscriminatedType = (node, value = {}) => {
291
291
  var mapAst = (ast, f) => {
292
292
  switch (ast._tag) {
293
293
  case "TypeLiteral":
294
- return new AST.TypeLiteral(ast.propertySignatures.map((prop) => new AST.PropertySignature(prop.name, f(prop.type), prop.isOptional, prop.isReadonly, prop.annotations)), ast.indexSignatures);
294
+ return new AST.TypeLiteral(ast.propertySignatures.map((prop) => new AST.PropertySignature(prop.name, f(prop.type, prop.name), prop.isOptional, prop.isReadonly, prop.annotations)), ast.indexSignatures);
295
295
  case "Union":
296
296
  return AST.Union.make(ast.types.map(f), ast.annotations);
297
297
  case "TupleType":
298
- return new AST.TupleType(ast.elements.map((t) => new AST.OptionalType(f(t.type), t.isOptional, t.annotations)), ast.rest.map((t) => new AST.Type(f(t.type), t.annotations)), ast.isReadonly, ast.annotations);
298
+ return new AST.TupleType(ast.elements.map((t, index) => new AST.OptionalType(f(t.type, index), t.isOptional, t.annotations)), ast.rest.map((t) => new AST.Type(f(t.type, void 0), t.annotations)), ast.isReadonly, ast.annotations);
299
299
  case "Suspend": {
300
- const newAst = f(ast.f());
300
+ const newAst = f(ast.f(), void 0);
301
301
  return new AST.Suspend(() => newAst, ast.annotations);
302
302
  }
303
303
  default:
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/index.ts", "../../../src/ast.ts", "../../../src/url.ts"],
4
- "sourcesContent": ["//\n// Copyright 2020 DXOS.org\n//\n\nimport { AST, JSONSchema, Schema as S } from '@effect/schema';\nimport type * as Types from 'effect/Types';\n\n// TODO(dmaretskyi): Remove re-exports.\nexport { AST, JSONSchema, S, Types };\n\nexport * from './ast';\nexport * from './url';\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { AST, Schema as S } from '@effect/schema';\nimport { Option, pipe } from 'effect';\n\nimport { invariant } from '@dxos/invariant';\nimport { nonNullable } from '@dxos/util';\n\n//\n// Refs\n// https://effect.website/docs/schema/introduction\n// https://www.npmjs.com/package/@effect/schema\n// https://effect-ts.github.io/effect/schema/AST.ts.html\n//\n\nexport type SimpleType = 'object' | 'string' | 'number' | 'boolean' | 'enum' | 'literal';\n\n/**\n * Get the base type; e.g., traverse through refinements.\n */\nexport const getSimpleType = (node: AST.AST): SimpleType | undefined => {\n if (AST.isObjectKeyword(node) || AST.isTypeLiteral(node) || isDiscriminatedUnion(node)) {\n return 'object';\n }\n\n if (AST.isStringKeyword(node)) {\n return 'string';\n }\n if (AST.isNumberKeyword(node)) {\n return 'number';\n }\n if (AST.isBooleanKeyword(node)) {\n return 'boolean';\n }\n\n if (AST.isEnums(node)) {\n return 'enum';\n }\n\n if (AST.isLiteral(node)) {\n return 'literal';\n }\n};\n\nexport const isSimpleType = (node: AST.AST): boolean => !!getSimpleType(node);\n\nexport namespace SimpleType {\n /**\n * Returns the default empty value for a given SimpleType.\n * Used for initializing new array values etc.\n */\n export const getDefaultValue = (type: SimpleType): any => {\n switch (type) {\n case 'string': {\n return '';\n }\n case 'number': {\n return 0;\n }\n case 'boolean': {\n return false;\n }\n case 'object': {\n return {};\n }\n default: {\n throw new Error(`Unsupported type for default value: ${type}`);\n }\n }\n };\n}\n\n//\n// Branded types\n//\n\nexport 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$]*)*/;\nconst PROP_REGEX = /\\w+/;\n\n/**\n * https://www.ietf.org/archive/id/draft-goessner-dispatch-jsonpath-00.html\n */\nexport const JsonPath = S.NonEmptyString.pipe(S.pattern(PATH_REGEX)) as any as S.Schema<JsonPath>;\nexport const JsonProp = S.NonEmptyString.pipe(S.pattern(PROP_REGEX)) as any as S.Schema<JsonProp>;\n\nexport enum VisitResult {\n CONTINUE = 0,\n /**\n * Skip visiting children.\n */\n SKIP = 1,\n /**\n * Stop traversing immediately.\n */\n EXIT = 2,\n}\n\nexport type Path = (string | number)[];\n\nexport type TestFn = (node: AST.AST, path: Path, depth: number) => VisitResult | boolean | undefined;\n\nexport type VisitorFn = (node: AST.AST, path: Path, depth: number) => void;\n\nconst defaultTest: TestFn = isSimpleType;\n\n/**\n * Visit leaf nodes.\n * Refs:\n * - https://github.com/syntax-tree/unist-util-visit?tab=readme-ov-file#visitor\n * - https://github.com/syntax-tree/unist-util-is?tab=readme-ov-file#test\n */\nexport const visit: {\n (node: AST.AST, visitor: VisitorFn): void;\n (node: AST.AST, test: TestFn, visitor: VisitorFn): void;\n} = (node: AST.AST, testOrVisitor: TestFn | VisitorFn, visitor?: VisitorFn): void => {\n if (!visitor) {\n visitNode(node, defaultTest, testOrVisitor);\n } else {\n visitNode(node, testOrVisitor as TestFn, visitor);\n }\n};\n\nconst visitNode = (\n node: AST.AST,\n test: TestFn | undefined,\n visitor: VisitorFn,\n path: Path = [],\n depth = 0,\n): VisitResult | undefined => {\n const _result = test?.(node, path, depth);\n const result: VisitResult =\n _result === undefined\n ? VisitResult.CONTINUE\n : typeof _result === 'boolean'\n ? _result\n ? VisitResult.CONTINUE\n : VisitResult.SKIP\n : _result;\n\n if (result === VisitResult.EXIT) {\n return result;\n }\n if (result !== VisitResult.SKIP) {\n visitor(node, path, depth);\n }\n\n // Object.\n if (AST.isTypeLiteral(node)) {\n for (const prop of AST.getPropertySignatures(node)) {\n const currentPath = [...path, prop.name.toString()];\n const result = visitNode(prop.type, test, visitor, currentPath, depth + 1);\n if (result === VisitResult.EXIT) {\n return result;\n }\n }\n }\n\n // Array.\n else if (AST.isTupleType(node)) {\n for (const [i, element] of node.elements.entries()) {\n const currentPath = [...path, i];\n const result = visitNode(element.type, test, visitor, currentPath, depth);\n if (result === VisitResult.EXIT) {\n return result;\n }\n }\n }\n\n // Branching union (e.g., optional, discriminated unions).\n else if (AST.isUnion(node)) {\n for (const type of node.types) {\n const result = visitNode(type, test, visitor, path, depth);\n if (result === VisitResult.EXIT) {\n return result;\n }\n }\n }\n\n // Refinement.\n else if (AST.isRefinement(node)) {\n const result = visitNode(node.from, test, visitor, path, depth);\n if (result === VisitResult.EXIT) {\n return result;\n }\n }\n\n // TODO(burdon): Transforms?\n};\n\n/**\n * Recursively descend into AST to find first node that passes the test.\n */\n// TODO(burdon): Rewrite using visitNode?\nexport const findNode = (node: AST.AST, test: (node: AST.AST) => boolean): AST.AST | undefined => {\n if (test(node)) {\n return node;\n }\n\n // Object.\n else if (AST.isTypeLiteral(node)) {\n for (const prop of AST.getPropertySignatures(node)) {\n const child = findNode(prop.type, test);\n if (child) {\n return child;\n }\n }\n }\n\n // Tuple.\n else if (AST.isTupleType(node)) {\n for (const [_, element] of node.elements.entries()) {\n const child = findNode(element.type, test);\n if (child) {\n return child;\n }\n }\n }\n\n // Branching union (e.g., optional, discriminated unions).\n else if (AST.isUnion(node)) {\n if (isOption(node)) {\n for (const type of node.types) {\n const child = findNode(type, test);\n if (child) {\n return child;\n }\n }\n }\n }\n\n // Refinement.\n else if (AST.isRefinement(node)) {\n return findNode(node.from, test);\n }\n};\n\n/**\n * Get the AST node for the given property (dot-path).\n */\nexport const findProperty = (schema: S.Schema<any>, path: JsonPath | JsonProp): AST.AST | undefined => {\n const getProp = (node: AST.AST, path: JsonProp[]): AST.AST | undefined => {\n const [name, ...rest] = path;\n const typeNode = findNode(node, AST.isTypeLiteral);\n invariant(typeNode);\n for (const prop of AST.getPropertySignatures(typeNode)) {\n if (prop.name === name) {\n if (rest.length) {\n return getProp(prop.type, rest);\n } else {\n return prop.type;\n }\n }\n }\n };\n\n return getProp(schema.ast, path.split('.') as JsonProp[]);\n};\n\n//\n// Annotations\n//\n\nconst defaultAnnotations: Record<string, AST.Annotated> = {\n ['ObjectKeyword' as const]: AST.objectKeyword,\n ['StringKeyword' as const]: AST.stringKeyword,\n ['NumberKeyword' as const]: AST.numberKeyword,\n ['BooleanKeyword' as const]: AST.booleanKeyword,\n};\n\n/**\n * Get annotation or return undefined.\n * @param annotationId\n * @param noDefault If true, then return undefined for effect library defined values.\n */\nexport const getAnnotation =\n <T>(annotationId: symbol, noDefault = true) =>\n (node: AST.AST): T | undefined => {\n // Title fallback seems to be the identifier.\n const id = pipe(AST.getIdentifierAnnotation(node), Option.getOrUndefined);\n const value = pipe(AST.getAnnotation<T>(annotationId)(node), Option.getOrUndefined);\n if (noDefault && (value === defaultAnnotations[node._tag]?.annotations[annotationId] || value === id)) {\n return undefined;\n }\n\n return value;\n };\n\n/**\n * Recursively descend into AST to find first matching annotations.\n * Optionally skips default annotations for basic types (e.g., 'a string').\n */\n// TODO(burdon): Convert to effect pattern (i.e., return operator like getAnnotation).\nexport const findAnnotation = <T>(node: AST.AST, annotationId: symbol, noDefault = true): T | undefined => {\n const getAnnotationById = getAnnotation(annotationId, noDefault);\n\n const getBaseAnnotation = (node: AST.AST): T | undefined => {\n const value = getAnnotationById(node);\n if (value !== undefined) {\n return value as T;\n }\n\n if (AST.isUnion(node)) {\n if (isOption(node)) {\n return getAnnotationById(node.types[0]) as T;\n }\n }\n };\n\n return getBaseAnnotation(node);\n};\n\n//\n// Unions\n//\n\n/**\n * Effect S.optional creates a union type with undefined as the second type.\n */\nexport const isOption = (node: AST.AST): boolean => {\n return AST.isUnion(node) && node.types.length === 2 && AST.isUndefinedKeyword(node.types[1]);\n};\n\n/**\n * Determines if the node is a union of literal types.\n */\nexport const isLiteralUnion = (node: AST.AST): boolean => {\n return AST.isUnion(node) && node.types.every(AST.isLiteral);\n};\n\n/**\n * Determines if the node is a discriminated union.\n */\nexport const isDiscriminatedUnion = (node: AST.AST): boolean => {\n return AST.isUnion(node) && !!getDiscriminatingProps(node)?.length;\n};\n\n/**\n * Get the discriminating properties for the given union type.\n */\nexport const getDiscriminatingProps = (node: AST.AST): string[] | undefined => {\n invariant(AST.isUnion(node));\n if (isOption(node)) {\n return;\n }\n\n // Get common literals across all types.\n return node.types.reduce<string[]>((shared, type) => {\n const props = AST.getPropertySignatures(type)\n // TODO(burdon): Should check each literal is unique.\n .filter((p) => AST.isLiteral(p.type))\n .map((p) => p.name.toString());\n\n // Return common literals.\n return shared.length === 0 ? props : shared.filter((prop) => props.includes(prop));\n }, []);\n};\n\n/**\n * Get the discriminated type for the given value.\n */\nexport const getDiscriminatedType = (node: AST.AST, value: Record<string, any> = {}): AST.AST | undefined => {\n invariant(AST.isUnion(node));\n invariant(value);\n const props = getDiscriminatingProps(node);\n if (!props?.length) {\n return;\n }\n\n // Match provided values.\n for (const type of node.types) {\n const match = AST.getPropertySignatures(type)\n .filter((prop) => props?.includes(prop.name.toString()))\n .every((prop) => {\n invariant(AST.isLiteral(prop.type));\n return prop.type.literal === value[prop.name.toString()];\n });\n\n if (match) {\n return type;\n }\n }\n\n // Create union of discriminating properties.\n // NOTE: This may not work with non-overlapping variants.\n // TODO(burdon): Iterate through props and knock-out variants that don't match.\n const fields = Object.fromEntries(\n props\n .map((prop) => {\n const literals = node.types\n .map((type) => {\n const literal = AST.getPropertySignatures(type).find((p) => p.name.toString() === prop)!;\n invariant(AST.isLiteral(literal.type));\n return literal.type.literal;\n })\n .filter(nonNullable);\n\n return literals.length ? [prop, S.Literal(...literals)] : undefined;\n })\n .filter(nonNullable),\n );\n\n const schema = S.Struct(fields);\n return schema.ast;\n};\n\n/**\n * Maps AST nodes.\n * The user is responsible for recursively calling {@link mapAst} on the AST.\n * NOTE: Will evaluate suspended ASTs.\n */\nexport const mapAst = (ast: AST.AST, f: (ast: AST.AST) => AST.AST): AST.AST => {\n switch (ast._tag) {\n case 'TypeLiteral':\n return new AST.TypeLiteral(\n ast.propertySignatures.map(\n (prop) =>\n new AST.PropertySignature(prop.name, f(prop.type), prop.isOptional, prop.isReadonly, prop.annotations),\n ),\n ast.indexSignatures,\n );\n case 'Union':\n return AST.Union.make(ast.types.map(f), ast.annotations);\n case 'TupleType':\n return new AST.TupleType(\n ast.elements.map((t) => new AST.OptionalType(f(t.type), t.isOptional, t.annotations)),\n ast.rest.map((t) => new AST.Type(f(t.type), t.annotations)),\n ast.isReadonly,\n ast.annotations,\n );\n case 'Suspend': {\n const newAst = f(ast.f());\n return new AST.Suspend(() => newAst, ast.annotations);\n }\n default:\n // TODO(dmaretskyi): Support more nodes.\n return ast;\n }\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { AST, type Schema as S } from '@effect/schema';\nimport { Option, pipe } from 'effect';\n\nimport { decamelize } from '@dxos/util';\n\nconst ParamKeyAnnotationId = Symbol.for('@dxos/schema/annotation/ParamKey');\n\ntype ParamKeyAnnotationValue = { key: string };\n\nexport const getParamKeyAnnotation: (annotated: AST.Annotated) => Option.Option<ParamKeyAnnotationValue> =\n AST.getAnnotation<ParamKeyAnnotationValue>(ParamKeyAnnotationId);\n\nexport const ParamKeyAnnotation =\n (value: ParamKeyAnnotationValue) =>\n <S extends S.Annotable.All>(self: S): S.Annotable.Self<S> =>\n self.annotations({ [ParamKeyAnnotationId]: value });\n\n/**\n * HTTP params parser.\n * Supports custom key serialization.\n */\nexport class UrlParser<T extends Record<string, any>> {\n constructor(private readonly _schema: S.Struct<T>) {}\n\n /**\n * Parse URL params.\n */\n parse(_url: string): T {\n const url = new URL(_url);\n return Object.entries(this._schema.fields).reduce<Record<string, any>>((params, [key, type]) => {\n let value = url.searchParams.get(decamelize(key));\n if (value == null) {\n value = url.searchParams.get(key);\n }\n\n if (value != null) {\n if (AST.isNumberKeyword(type.ast)) {\n params[key] = parseInt(value);\n } else if (AST.isBooleanKeyword(type.ast)) {\n params[key] = value === 'true' || value === '1';\n } else {\n params[key] = value;\n }\n }\n\n return params;\n }, {}) as T;\n }\n\n /**\n * Return URL with encoded params.\n */\n create(_url: string, params: T): URL {\n const url = new URL(_url);\n Object.entries(params).forEach(([key, value]) => {\n if (value !== undefined) {\n const field = this._schema.fields[key];\n if (field) {\n const { key: serializedKey } = pipe(\n getParamKeyAnnotation(field.ast),\n Option.getOrElse(() => ({\n key: decamelize(key),\n })),\n );\n\n url.searchParams.set(serializedKey, String(value));\n }\n }\n });\n\n return url;\n }\n}\n"],
5
- "mappings": ";;;AAIA,SAASA,OAAAA,MAAKC,YAAYC,UAAUC,UAAS;;;ACA7C,SAASC,KAAKC,UAAUC,SAAS;AACjC,SAASC,QAAQC,YAAY;AAE7B,SAASC,iBAAiB;AAC1B,SAASC,mBAAmB;;AAcrB,IAAMC,gBAAgB,CAACC,SAAAA;AAC5B,MAAIR,IAAIS,gBAAgBD,IAAAA,KAASR,IAAIU,cAAcF,IAAAA,KAASG,qBAAqBH,IAAAA,GAAO;AACtF,WAAO;EACT;AAEA,MAAIR,IAAIY,gBAAgBJ,IAAAA,GAAO;AAC7B,WAAO;EACT;AACA,MAAIR,IAAIa,gBAAgBL,IAAAA,GAAO;AAC7B,WAAO;EACT;AACA,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A,aAAOc;IACT,GAAG,CAAC,CAAA;EACN;;;;EAKAU,OAAOjB,MAAcO,QAAgB;AACnC,UAAMN,MAAM,IAAIC,IAAIF,IAAAA;AACpBG,WAAOC,QAAQG,MAAAA,EAAQW,QAAQ,CAAC,CAACV,KAAKf,KAAAA,MAAM;AAC1C,UAAIA,UAAU0B,QAAW;AACvB,cAAMC,QAAQ,KAAKtB,QAAQO,OAAOG,GAAAA;AAClC,YAAIY,OAAO;AACT,gBAAM,EAAEZ,KAAKa,cAAa,IAAKC,MAC7BjC,sBAAsB+B,MAAMN,GAAG,GAC/BS,QAAOC,UAAU,OAAO;YACtBhB,KAAKI,WAAWJ,GAAAA;UAClB,EAAA,CAAA;AAGFP,cAAIS,aAAae,IAAIJ,eAAeK,OAAOjC,KAAAA,CAAAA;QAC7C;MACF;IACF,CAAA;AAEA,WAAOQ;EACT;AACF;",
6
- "names": ["AST", "JSONSchema", "Schema", "S", "AST", "Schema", "S", "Option", "pipe", "invariant", "nonNullable", "getSimpleType", "node", "isObjectKeyword", "isTypeLiteral", "isDiscriminatedUnion", "isStringKeyword", "isNumberKeyword", "isBooleanKeyword", "isEnums", "isLiteral", "isSimpleType", "SimpleType", "getDefaultValue", "type", "Error", "PATH_REGEX", "PROP_REGEX", "JsonPath", "NonEmptyString", "pattern", "JsonProp", "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", "OptionalType", "Type", "newAst", "Suspend", "AST", "Option", "pipe", "decamelize", "ParamKeyAnnotationId", "Symbol", "for", "getParamKeyAnnotation", "AST", "getAnnotation", "ParamKeyAnnotation", "value", "self", "annotations", "UrlParser", "constructor", "_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 2020 DXOS.org\n//\n\nimport { AST, JSONSchema, Schema as S } from '@effect/schema';\nimport type * as Types from 'effect/Types';\n\n// TODO(dmaretskyi): Remove re-exports.\nexport { AST, JSONSchema, S, Types };\n\nexport * from './ast';\nexport * from './url';\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { AST, Schema as S } from '@effect/schema';\nimport { Option, pipe } from 'effect';\n\nimport { invariant } from '@dxos/invariant';\nimport { nonNullable } from '@dxos/util';\n\n//\n// Refs\n// https://effect.website/docs/schema/introduction\n// https://www.npmjs.com/package/@effect/schema\n// https://effect-ts.github.io/effect/schema/AST.ts.html\n//\n\nexport type SimpleType = 'object' | 'string' | 'number' | 'boolean' | 'enum' | 'literal';\n\n/**\n * Get the base type; e.g., traverse through refinements.\n */\nexport const getSimpleType = (node: AST.AST): SimpleType | undefined => {\n if (AST.isObjectKeyword(node) || AST.isTypeLiteral(node) || isDiscriminatedUnion(node) || AST.isDeclaration(node)) {\n return 'object';\n }\n\n if (AST.isStringKeyword(node)) {\n return 'string';\n }\n if (AST.isNumberKeyword(node)) {\n return 'number';\n }\n if (AST.isBooleanKeyword(node)) {\n return 'boolean';\n }\n\n if (AST.isEnums(node)) {\n return 'enum';\n }\n\n if (AST.isLiteral(node)) {\n return 'literal';\n }\n};\n\nexport const isSimpleType = (node: AST.AST): boolean => !!getSimpleType(node);\n\nexport namespace SimpleType {\n /**\n * Returns the default empty value for a given SimpleType.\n * Used for initializing new array values etc.\n */\n export const getDefaultValue = (type: SimpleType): any => {\n switch (type) {\n case 'string': {\n return '';\n }\n case 'number': {\n return 0;\n }\n case 'boolean': {\n return false;\n }\n case 'object': {\n return {};\n }\n default: {\n throw new Error(`Unsupported type for default value: ${type}`);\n }\n }\n };\n}\n\n//\n// Branded types\n//\n\nexport type JsonProp = string & { __JsonPath: true; __JsonProp: true };\nexport type JsonPath = string & { __JsonPath: true };\n\nconst PATH_REGEX = /^[a-zA-Z_$][\\w$]*(?:\\.[a-zA-Z_$][\\w$]*|\\[\\d+\\])*$/;\nconst PROP_REGEX = /\\w+/;\n\n/**\n * https://www.ietf.org/archive/id/draft-goessner-dispatch-jsonpath-00.html\n */\nexport const JsonPath = S.NonEmptyString.pipe(S.pattern(PATH_REGEX)) as any as S.Schema<JsonPath>;\nexport const JsonProp = S.NonEmptyString.pipe(S.pattern(PROP_REGEX)) as any as S.Schema<JsonProp>;\n\nexport enum VisitResult {\n CONTINUE = 0,\n /**\n * Skip visiting children.\n */\n SKIP = 1,\n /**\n * Stop traversing immediately.\n */\n EXIT = 2,\n}\n\nexport type Path = (string | number)[];\n\nexport type TestFn = (node: AST.AST, path: Path, depth: number) => VisitResult | boolean | undefined;\n\nexport type VisitorFn = (node: AST.AST, path: Path, depth: number) => void;\n\nconst defaultTest: TestFn = isSimpleType;\n\n/**\n * Visit leaf nodes.\n * Refs:\n * - https://github.com/syntax-tree/unist-util-visit?tab=readme-ov-file#visitor\n * - https://github.com/syntax-tree/unist-util-is?tab=readme-ov-file#test\n */\nexport const visit: {\n (node: AST.AST, visitor: VisitorFn): void;\n (node: AST.AST, test: TestFn, visitor: VisitorFn): void;\n} = (node: AST.AST, testOrVisitor: TestFn | VisitorFn, visitor?: VisitorFn): void => {\n if (!visitor) {\n visitNode(node, defaultTest, testOrVisitor);\n } else {\n visitNode(node, testOrVisitor as TestFn, visitor);\n }\n};\n\nconst visitNode = (\n node: AST.AST,\n test: TestFn | undefined,\n visitor: VisitorFn,\n path: Path = [],\n depth = 0,\n): VisitResult | undefined => {\n const _result = test?.(node, path, depth);\n const result: VisitResult =\n _result === undefined\n ? VisitResult.CONTINUE\n : typeof _result === 'boolean'\n ? _result\n ? VisitResult.CONTINUE\n : VisitResult.SKIP\n : _result;\n\n if (result === VisitResult.EXIT) {\n return result;\n }\n if (result !== VisitResult.SKIP) {\n visitor(node, path, depth);\n }\n\n // Object.\n if (AST.isTypeLiteral(node)) {\n for (const prop of AST.getPropertySignatures(node)) {\n const currentPath = [...path, prop.name.toString()];\n const result = visitNode(prop.type, test, visitor, currentPath, depth + 1);\n if (result === VisitResult.EXIT) {\n return result;\n }\n }\n }\n\n // Array.\n else if (AST.isTupleType(node)) {\n for (const [i, element] of node.elements.entries()) {\n const currentPath = [...path, i];\n const result = visitNode(element.type, test, visitor, currentPath, depth);\n if (result === VisitResult.EXIT) {\n return result;\n }\n }\n }\n\n // Branching union (e.g., optional, discriminated unions).\n else if (AST.isUnion(node)) {\n for (const type of node.types) {\n const result = visitNode(type, test, visitor, path, depth);\n if (result === VisitResult.EXIT) {\n return result;\n }\n }\n }\n\n // Refinement.\n else if (AST.isRefinement(node)) {\n const result = visitNode(node.from, test, visitor, path, depth);\n if (result === VisitResult.EXIT) {\n return result;\n }\n }\n\n // TODO(burdon): Transforms?\n};\n\n/**\n * Recursively descend into AST to find first node that passes the test.\n */\n// TODO(burdon): Rewrite using visitNode?\nexport const findNode = (node: AST.AST, test: (node: AST.AST) => boolean): AST.AST | undefined => {\n if (test(node)) {\n return node;\n }\n\n // Object.\n else if (AST.isTypeLiteral(node)) {\n for (const prop of AST.getPropertySignatures(node)) {\n const child = findNode(prop.type, test);\n if (child) {\n return child;\n }\n }\n }\n\n // Tuple.\n else if (AST.isTupleType(node)) {\n for (const [_, element] of node.elements.entries()) {\n const child = findNode(element.type, test);\n if (child) {\n return child;\n }\n }\n }\n\n // Branching union (e.g., optional, discriminated unions).\n else if (AST.isUnion(node)) {\n if (isOption(node)) {\n for (const type of node.types) {\n const child = findNode(type, test);\n if (child) {\n return child;\n }\n }\n }\n }\n\n // Refinement.\n else if (AST.isRefinement(node)) {\n return findNode(node.from, test);\n }\n};\n\n/**\n * Get the AST node for the given property (dot-path).\n */\nexport const findProperty = (schema: S.Schema<any>, path: JsonPath | JsonProp): AST.AST | undefined => {\n const getProp = (node: AST.AST, path: JsonProp[]): AST.AST | undefined => {\n const [name, ...rest] = path;\n const typeNode = findNode(node, AST.isTypeLiteral);\n invariant(typeNode);\n for (const prop of AST.getPropertySignatures(typeNode)) {\n if (prop.name === name) {\n if (rest.length) {\n return getProp(prop.type, rest);\n } else {\n return prop.type;\n }\n }\n }\n };\n\n return getProp(schema.ast, path.split('.') as JsonProp[]);\n};\n\n//\n// Annotations\n//\n\nconst defaultAnnotations: Record<string, AST.Annotated> = {\n ['ObjectKeyword' as const]: AST.objectKeyword,\n ['StringKeyword' as const]: AST.stringKeyword,\n ['NumberKeyword' as const]: AST.numberKeyword,\n ['BooleanKeyword' as const]: AST.booleanKeyword,\n};\n\n/**\n * Get annotation or return undefined.\n * @param annotationId\n * @param noDefault If true, then return undefined for effect library defined values.\n */\nexport const getAnnotation =\n <T>(annotationId: symbol, noDefault = true) =>\n (node: AST.AST): T | undefined => {\n // Title fallback seems to be the identifier.\n const id = pipe(AST.getIdentifierAnnotation(node), Option.getOrUndefined);\n const value = pipe(AST.getAnnotation<T>(annotationId)(node), Option.getOrUndefined);\n if (noDefault && (value === defaultAnnotations[node._tag]?.annotations[annotationId] || value === id)) {\n return undefined;\n }\n\n return value;\n };\n\n/**\n * Recursively descend into AST to find first matching annotations.\n * Optionally skips default annotations for basic types (e.g., 'a string').\n */\n// TODO(burdon): Convert to effect pattern (i.e., return operator like getAnnotation).\nexport const findAnnotation = <T>(node: AST.AST, annotationId: symbol, noDefault = true): T | undefined => {\n const getAnnotationById = getAnnotation(annotationId, noDefault);\n\n const getBaseAnnotation = (node: AST.AST): T | undefined => {\n const value = getAnnotationById(node);\n if (value !== undefined) {\n return value as T;\n }\n\n if (AST.isUnion(node)) {\n if (isOption(node)) {\n return getAnnotationById(node.types[0]) as T;\n }\n }\n };\n\n return getBaseAnnotation(node);\n};\n\n//\n// Unions\n//\n\n/**\n * Effect S.optional creates a union type with undefined as the second type.\n */\nexport const isOption = (node: AST.AST): boolean => {\n return AST.isUnion(node) && node.types.length === 2 && AST.isUndefinedKeyword(node.types[1]);\n};\n\n/**\n * Determines if the node is a union of literal types.\n */\nexport const isLiteralUnion = (node: AST.AST): boolean => {\n return AST.isUnion(node) && node.types.every(AST.isLiteral);\n};\n\n/**\n * Determines if the node is a discriminated union.\n */\nexport const isDiscriminatedUnion = (node: AST.AST): boolean => {\n return AST.isUnion(node) && !!getDiscriminatingProps(node)?.length;\n};\n\n/**\n * Get the discriminating properties for the given union type.\n */\nexport const getDiscriminatingProps = (node: AST.AST): string[] | undefined => {\n invariant(AST.isUnion(node));\n if (isOption(node)) {\n return;\n }\n\n // Get common literals across all types.\n return node.types.reduce<string[]>((shared, type) => {\n const props = AST.getPropertySignatures(type)\n // TODO(burdon): Should check each literal is unique.\n .filter((p) => AST.isLiteral(p.type))\n .map((p) => p.name.toString());\n\n // Return common literals.\n return shared.length === 0 ? props : shared.filter((prop) => props.includes(prop));\n }, []);\n};\n\n/**\n * Get the discriminated type for the given value.\n */\nexport const getDiscriminatedType = (node: AST.AST, value: Record<string, any> = {}): AST.AST | undefined => {\n invariant(AST.isUnion(node));\n invariant(value);\n const props = getDiscriminatingProps(node);\n if (!props?.length) {\n return;\n }\n\n // Match provided values.\n for (const type of node.types) {\n const match = AST.getPropertySignatures(type)\n .filter((prop) => props?.includes(prop.name.toString()))\n .every((prop) => {\n invariant(AST.isLiteral(prop.type));\n return prop.type.literal === value[prop.name.toString()];\n });\n\n if (match) {\n return type;\n }\n }\n\n // Create union of discriminating properties.\n // NOTE: This may not work with non-overlapping variants.\n // TODO(burdon): Iterate through props and knock-out variants that don't match.\n const fields = Object.fromEntries(\n props\n .map((prop) => {\n const literals = node.types\n .map((type) => {\n const literal = AST.getPropertySignatures(type).find((p) => p.name.toString() === prop)!;\n invariant(AST.isLiteral(literal.type));\n return literal.type.literal;\n })\n .filter(nonNullable);\n\n return literals.length ? [prop, S.Literal(...literals)] : undefined;\n })\n .filter(nonNullable),\n );\n\n const schema = S.Struct(fields);\n return schema.ast;\n};\n\n/**\n * Maps AST nodes.\n * The user is responsible for recursively calling {@link mapAst} on the AST.\n * NOTE: Will evaluate suspended ASTs.\n */\nexport const mapAst = (ast: AST.AST, f: (ast: AST.AST, key: keyof any | undefined) => AST.AST): AST.AST => {\n switch (ast._tag) {\n case 'TypeLiteral':\n return new AST.TypeLiteral(\n ast.propertySignatures.map(\n (prop) =>\n new AST.PropertySignature(\n prop.name,\n f(prop.type, prop.name),\n prop.isOptional,\n prop.isReadonly,\n prop.annotations,\n ),\n ),\n ast.indexSignatures,\n );\n case 'Union':\n return AST.Union.make(ast.types.map(f), ast.annotations);\n case 'TupleType':\n return new AST.TupleType(\n ast.elements.map((t, index) => new AST.OptionalType(f(t.type, index), t.isOptional, t.annotations)),\n ast.rest.map((t) => new AST.Type(f(t.type, undefined), t.annotations)),\n ast.isReadonly,\n ast.annotations,\n );\n case 'Suspend': {\n const newAst = f(ast.f(), undefined);\n return new AST.Suspend(() => newAst, ast.annotations);\n }\n default:\n // TODO(dmaretskyi): Support more nodes.\n return ast;\n }\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { AST, type Schema as S } from '@effect/schema';\nimport { Option, pipe } from 'effect';\n\nimport { decamelize } from '@dxos/util';\n\nconst ParamKeyAnnotationId = Symbol.for('@dxos/schema/annotation/ParamKey');\n\ntype ParamKeyAnnotationValue = { key: string };\n\nexport const getParamKeyAnnotation: (annotated: AST.Annotated) => Option.Option<ParamKeyAnnotationValue> =\n AST.getAnnotation<ParamKeyAnnotationValue>(ParamKeyAnnotationId);\n\nexport const ParamKeyAnnotation =\n (value: ParamKeyAnnotationValue) =>\n <S extends S.Annotable.All>(self: S): S.Annotable.Self<S> =>\n self.annotations({ [ParamKeyAnnotationId]: value });\n\n/**\n * HTTP params parser.\n * Supports custom key serialization.\n */\nexport class UrlParser<T extends Record<string, any>> {\n constructor(private readonly _schema: S.Struct<T>) {}\n\n /**\n * Parse URL params.\n */\n parse(_url: string): T {\n const url = new URL(_url);\n return Object.entries(this._schema.fields).reduce<Record<string, any>>((params, [key, type]) => {\n let value = url.searchParams.get(decamelize(key));\n if (value == null) {\n value = url.searchParams.get(key);\n }\n\n if (value != null) {\n if (AST.isNumberKeyword(type.ast)) {\n params[key] = parseInt(value);\n } else if (AST.isBooleanKeyword(type.ast)) {\n params[key] = value === 'true' || value === '1';\n } else {\n params[key] = value;\n }\n }\n\n return params;\n }, {}) as T;\n }\n\n /**\n * Return URL with encoded params.\n */\n create(_url: string, params: T): URL {\n const url = new URL(_url);\n Object.entries(params).forEach(([key, value]) => {\n if (value !== undefined) {\n const field = this._schema.fields[key];\n if (field) {\n const { key: serializedKey } = pipe(\n getParamKeyAnnotation(field.ast),\n Option.getOrElse(() => ({\n key: decamelize(key),\n })),\n );\n\n url.searchParams.set(serializedKey, String(value));\n }\n }\n });\n\n return url;\n }\n}\n"],
5
+ "mappings": ";;;AAIA,SAASA,OAAAA,MAAKC,YAAYC,UAAUC,UAAS;;;ACA7C,SAASC,KAAKC,UAAUC,SAAS;AACjC,SAASC,QAAQC,YAAY;AAE7B,SAASC,iBAAiB;AAC1B,SAASC,mBAAmB;;AAcrB,IAAMC,gBAAgB,CAACC,SAAAA;AAC5B,MAAIR,IAAIS,gBAAgBD,IAAAA,KAASR,IAAIU,cAAcF,IAAAA,KAASG,qBAAqBH,IAAAA,KAASR,IAAIY,cAAcJ,I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jCP,iBAAOC,GAAAA,IAAOO,SAAStB,KAAAA;QACzB,WAAWH,KAAI0B,iBAAiBP,KAAKK,GAAG,GAAG;AACzCP,iBAAOC,GAAAA,IAAOf,UAAU,UAAUA,UAAU;QAC9C,OAAO;AACLc,iBAAOC,GAAAA,IAAOf;QAChB;MACF;AAEA,aAAOc;IACT,GAAG,CAAC,CAAA;EACN;;;;EAKAU,OAAOjB,MAAcO,QAAgB;AACnC,UAAMN,MAAM,IAAIC,IAAIF,IAAAA;AACpBG,WAAOC,QAAQG,MAAAA,EAAQW,QAAQ,CAAC,CAACV,KAAKf,KAAAA,MAAM;AAC1C,UAAIA,UAAU0B,QAAW;AACvB,cAAMC,QAAQ,KAAKtB,QAAQO,OAAOG,GAAAA;AAClC,YAAIY,OAAO;AACT,gBAAM,EAAEZ,KAAKa,cAAa,IAAKC,MAC7BjC,sBAAsB+B,MAAMN,GAAG,GAC/BS,QAAOC,UAAU,OAAO;YACtBhB,KAAKI,WAAWJ,GAAAA;UAClB,EAAA,CAAA;AAGFP,cAAIS,aAAae,IAAIJ,eAAeK,OAAOjC,KAAAA,CAAAA;QAC7C;MACF;IACF,CAAA;AAEA,WAAOQ;EACT;AACF;",
6
+ "names": ["AST", "JSONSchema", "Schema", "S", "AST", "Schema", "S", "Option", "pipe", "invariant", "nonNullable", "getSimpleType", "node", "isObjectKeyword", "isTypeLiteral", "isDiscriminatedUnion", "isDeclaration", "isStringKeyword", "isNumberKeyword", "isBooleanKeyword", "isEnums", "isLiteral", "isSimpleType", "SimpleType", "getDefaultValue", "type", "Error", "PATH_REGEX", "PROP_REGEX", "JsonPath", "NonEmptyString", "pattern", "JsonProp", "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", "AST", "Option", "pipe", "decamelize", "ParamKeyAnnotationId", "Symbol", "for", "getParamKeyAnnotation", "AST", "getAnnotation", "ParamKeyAnnotation", "value", "self", "annotations", "UrlParser", "constructor", "_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":41444,"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/effect/src/url.ts":{"bytes":7711,"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/effect/src/index.ts":{"bytes":1150,"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"packages/common/effect/src/ast.ts","kind":"import-statement","original":"./ast"},{"path":"packages/common/effect/src/url.ts","kind":"import-statement","original":"./url"}],"format":"esm"}},"outputs":{"packages/common/effect/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":25493},"packages/common/effect/dist/lib/browser/index.mjs":{"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["AST","JSONSchema","JsonPath","JsonProp","ParamKeyAnnotation","S","SimpleType","UrlParser","VisitResult","findAnnotation","findNode","findProperty","getAnnotation","getDiscriminatedType","getDiscriminatingProps","getParamKeyAnnotation","getSimpleType","isDiscriminatedUnion","isLiteralUnion","isOption","isSimpleType","mapAst","visit"],"entryPoint":"packages/common/effect/src/index.ts","inputs":{"packages/common/effect/src/index.ts":{"bytesInOutput":72},"packages/common/effect/src/ast.ts":{"bytesInOutput":8647},"packages/common/effect/src/url.ts":{"bytesInOutput":1624}},"bytes":10910}}}
1
+ {"inputs":{"packages/common/effect/src/ast.ts":{"bytes":41924,"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/effect/src/url.ts":{"bytes":7711,"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/effect/src/index.ts":{"bytes":1150,"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"packages/common/effect/src/ast.ts","kind":"import-statement","original":"./ast"},{"path":"packages/common/effect/src/url.ts","kind":"import-statement","original":"./url"}],"format":"esm"}},"outputs":{"packages/common/effect/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":25791},"packages/common/effect/dist/lib/browser/index.mjs":{"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["AST","JSONSchema","JsonPath","JsonProp","ParamKeyAnnotation","S","SimpleType","UrlParser","VisitResult","findAnnotation","findNode","findProperty","getAnnotation","getDiscriminatedType","getDiscriminatingProps","getParamKeyAnnotation","getSimpleType","isDiscriminatedUnion","isLiteralUnion","isOption","isSimpleType","mapAst","visit"],"entryPoint":"packages/common/effect/src/index.ts","inputs":{"packages/common/effect/src/index.ts":{"bytesInOutput":72},"packages/common/effect/src/ast.ts":{"bytesInOutput":8725},"packages/common/effect/src/url.ts":{"bytesInOutput":1624}},"bytes":10988}}}
@@ -53,7 +53,7 @@ var import_effect2 = require("effect");
53
53
  var import_util2 = require("@dxos/util");
54
54
  var __dxlog_file = "/home/runner/work/dxos/dxos/packages/common/effect/src/ast.ts";
55
55
  var getSimpleType = (node) => {
56
- if (import_schema2.AST.isObjectKeyword(node) || import_schema2.AST.isTypeLiteral(node) || isDiscriminatedUnion(node)) {
56
+ if (import_schema2.AST.isObjectKeyword(node) || import_schema2.AST.isTypeLiteral(node) || isDiscriminatedUnion(node) || import_schema2.AST.isDeclaration(node)) {
57
57
  return "object";
58
58
  }
59
59
  if (import_schema2.AST.isStringKeyword(node)) {
@@ -95,7 +95,7 @@ var SimpleType;
95
95
  }
96
96
  };
97
97
  })(SimpleType || (SimpleType = {}));
98
- var PATH_REGEX = /[a-zA-Z_$][\w$]*(?:\.[a-zA-Z_$][\w$]*)*/;
98
+ var PATH_REGEX = /^[a-zA-Z_$][\w$]*(?:\.[a-zA-Z_$][\w$]*|\[\d+\])*$/;
99
99
  var PROP_REGEX = /\w+/;
100
100
  var JsonPath = import_schema2.Schema.NonEmptyString.pipe(import_schema2.Schema.pattern(PATH_REGEX));
101
101
  var JsonProp = import_schema2.Schema.NonEmptyString.pipe(import_schema2.Schema.pattern(PROP_REGEX));
@@ -334,13 +334,13 @@ var getDiscriminatedType = (node, value = {}) => {
334
334
  var mapAst = (ast, f) => {
335
335
  switch (ast._tag) {
336
336
  case "TypeLiteral":
337
- return new import_schema2.AST.TypeLiteral(ast.propertySignatures.map((prop) => new import_schema2.AST.PropertySignature(prop.name, f(prop.type), prop.isOptional, prop.isReadonly, prop.annotations)), ast.indexSignatures);
337
+ return new import_schema2.AST.TypeLiteral(ast.propertySignatures.map((prop) => new import_schema2.AST.PropertySignature(prop.name, f(prop.type, prop.name), prop.isOptional, prop.isReadonly, prop.annotations)), ast.indexSignatures);
338
338
  case "Union":
339
339
  return import_schema2.AST.Union.make(ast.types.map(f), ast.annotations);
340
340
  case "TupleType":
341
- return new import_schema2.AST.TupleType(ast.elements.map((t) => new import_schema2.AST.OptionalType(f(t.type), t.isOptional, t.annotations)), ast.rest.map((t) => new import_schema2.AST.Type(f(t.type), t.annotations)), ast.isReadonly, ast.annotations);
341
+ return new import_schema2.AST.TupleType(ast.elements.map((t, index) => new import_schema2.AST.OptionalType(f(t.type, index), t.isOptional, t.annotations)), ast.rest.map((t) => new import_schema2.AST.Type(f(t.type, void 0), t.annotations)), ast.isReadonly, ast.annotations);
342
342
  case "Suspend": {
343
- const newAst = f(ast.f());
343
+ const newAst = f(ast.f(), void 0);
344
344
  return new import_schema2.AST.Suspend(() => newAst, ast.annotations);
345
345
  }
346
346
  default:
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/index.ts", "../../../src/ast.ts", "../../../src/url.ts"],
4
- "sourcesContent": ["//\n// Copyright 2020 DXOS.org\n//\n\nimport { AST, JSONSchema, Schema as S } from '@effect/schema';\nimport type * as Types from 'effect/Types';\n\n// TODO(dmaretskyi): Remove re-exports.\nexport { AST, JSONSchema, S, Types };\n\nexport * from './ast';\nexport * from './url';\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { AST, Schema as S } from '@effect/schema';\nimport { Option, pipe } from 'effect';\n\nimport { invariant } from '@dxos/invariant';\nimport { nonNullable } from '@dxos/util';\n\n//\n// Refs\n// https://effect.website/docs/schema/introduction\n// https://www.npmjs.com/package/@effect/schema\n// https://effect-ts.github.io/effect/schema/AST.ts.html\n//\n\nexport type SimpleType = 'object' | 'string' | 'number' | 'boolean' | 'enum' | 'literal';\n\n/**\n * Get the base type; e.g., traverse through refinements.\n */\nexport const getSimpleType = (node: AST.AST): SimpleType | undefined => {\n if (AST.isObjectKeyword(node) || AST.isTypeLiteral(node) || isDiscriminatedUnion(node)) {\n return 'object';\n }\n\n if (AST.isStringKeyword(node)) {\n return 'string';\n }\n if (AST.isNumberKeyword(node)) {\n return 'number';\n }\n if (AST.isBooleanKeyword(node)) {\n return 'boolean';\n }\n\n if (AST.isEnums(node)) {\n return 'enum';\n }\n\n if (AST.isLiteral(node)) {\n return 'literal';\n }\n};\n\nexport const isSimpleType = (node: AST.AST): boolean => !!getSimpleType(node);\n\nexport namespace SimpleType {\n /**\n * Returns the default empty value for a given SimpleType.\n * Used for initializing new array values etc.\n */\n export const getDefaultValue = (type: SimpleType): any => {\n switch (type) {\n case 'string': {\n return '';\n }\n case 'number': {\n return 0;\n }\n case 'boolean': {\n return false;\n }\n case 'object': {\n return {};\n }\n default: {\n throw new Error(`Unsupported type for default value: ${type}`);\n }\n }\n };\n}\n\n//\n// Branded types\n//\n\nexport 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$]*)*/;\nconst PROP_REGEX = /\\w+/;\n\n/**\n * https://www.ietf.org/archive/id/draft-goessner-dispatch-jsonpath-00.html\n */\nexport const JsonPath = S.NonEmptyString.pipe(S.pattern(PATH_REGEX)) as any as S.Schema<JsonPath>;\nexport const JsonProp = S.NonEmptyString.pipe(S.pattern(PROP_REGEX)) as any as S.Schema<JsonProp>;\n\nexport enum VisitResult {\n CONTINUE = 0,\n /**\n * Skip visiting children.\n */\n SKIP = 1,\n /**\n * Stop traversing immediately.\n */\n EXIT = 2,\n}\n\nexport type Path = (string | number)[];\n\nexport type TestFn = (node: AST.AST, path: Path, depth: number) => VisitResult | boolean | undefined;\n\nexport type VisitorFn = (node: AST.AST, path: Path, depth: number) => void;\n\nconst defaultTest: TestFn = isSimpleType;\n\n/**\n * Visit leaf nodes.\n * Refs:\n * - https://github.com/syntax-tree/unist-util-visit?tab=readme-ov-file#visitor\n * - https://github.com/syntax-tree/unist-util-is?tab=readme-ov-file#test\n */\nexport const visit: {\n (node: AST.AST, visitor: VisitorFn): void;\n (node: AST.AST, test: TestFn, visitor: VisitorFn): void;\n} = (node: AST.AST, testOrVisitor: TestFn | VisitorFn, visitor?: VisitorFn): void => {\n if (!visitor) {\n visitNode(node, defaultTest, testOrVisitor);\n } else {\n visitNode(node, testOrVisitor as TestFn, visitor);\n }\n};\n\nconst visitNode = (\n node: AST.AST,\n test: TestFn | undefined,\n visitor: VisitorFn,\n path: Path = [],\n depth = 0,\n): VisitResult | undefined => {\n const _result = test?.(node, path, depth);\n const result: VisitResult =\n _result === undefined\n ? VisitResult.CONTINUE\n : typeof _result === 'boolean'\n ? _result\n ? VisitResult.CONTINUE\n : VisitResult.SKIP\n : _result;\n\n if (result === VisitResult.EXIT) {\n return result;\n }\n if (result !== VisitResult.SKIP) {\n visitor(node, path, depth);\n }\n\n // Object.\n if (AST.isTypeLiteral(node)) {\n for (const prop of AST.getPropertySignatures(node)) {\n const currentPath = [...path, prop.name.toString()];\n const result = visitNode(prop.type, test, visitor, currentPath, depth + 1);\n if (result === VisitResult.EXIT) {\n return result;\n }\n }\n }\n\n // Array.\n else if (AST.isTupleType(node)) {\n for (const [i, element] of node.elements.entries()) {\n const currentPath = [...path, i];\n const result = visitNode(element.type, test, visitor, currentPath, depth);\n if (result === VisitResult.EXIT) {\n return result;\n }\n }\n }\n\n // Branching union (e.g., optional, discriminated unions).\n else if (AST.isUnion(node)) {\n for (const type of node.types) {\n const result = visitNode(type, test, visitor, path, depth);\n if (result === VisitResult.EXIT) {\n return result;\n }\n }\n }\n\n // Refinement.\n else if (AST.isRefinement(node)) {\n const result = visitNode(node.from, test, visitor, path, depth);\n if (result === VisitResult.EXIT) {\n return result;\n }\n }\n\n // TODO(burdon): Transforms?\n};\n\n/**\n * Recursively descend into AST to find first node that passes the test.\n */\n// TODO(burdon): Rewrite using visitNode?\nexport const findNode = (node: AST.AST, test: (node: AST.AST) => boolean): AST.AST | undefined => {\n if (test(node)) {\n return node;\n }\n\n // Object.\n else if (AST.isTypeLiteral(node)) {\n for (const prop of AST.getPropertySignatures(node)) {\n const child = findNode(prop.type, test);\n if (child) {\n return child;\n }\n }\n }\n\n // Tuple.\n else if (AST.isTupleType(node)) {\n for (const [_, element] of node.elements.entries()) {\n const child = findNode(element.type, test);\n if (child) {\n return child;\n }\n }\n }\n\n // Branching union (e.g., optional, discriminated unions).\n else if (AST.isUnion(node)) {\n if (isOption(node)) {\n for (const type of node.types) {\n const child = findNode(type, test);\n if (child) {\n return child;\n }\n }\n }\n }\n\n // Refinement.\n else if (AST.isRefinement(node)) {\n return findNode(node.from, test);\n }\n};\n\n/**\n * Get the AST node for the given property (dot-path).\n */\nexport const findProperty = (schema: S.Schema<any>, path: JsonPath | JsonProp): AST.AST | undefined => {\n const getProp = (node: AST.AST, path: JsonProp[]): AST.AST | undefined => {\n const [name, ...rest] = path;\n const typeNode = findNode(node, AST.isTypeLiteral);\n invariant(typeNode);\n for (const prop of AST.getPropertySignatures(typeNode)) {\n if (prop.name === name) {\n if (rest.length) {\n return getProp(prop.type, rest);\n } else {\n return prop.type;\n }\n }\n }\n };\n\n return getProp(schema.ast, path.split('.') as JsonProp[]);\n};\n\n//\n// Annotations\n//\n\nconst defaultAnnotations: Record<string, AST.Annotated> = {\n ['ObjectKeyword' as const]: AST.objectKeyword,\n ['StringKeyword' as const]: AST.stringKeyword,\n ['NumberKeyword' as const]: AST.numberKeyword,\n ['BooleanKeyword' as const]: AST.booleanKeyword,\n};\n\n/**\n * Get annotation or return undefined.\n * @param annotationId\n * @param noDefault If true, then return undefined for effect library defined values.\n */\nexport const getAnnotation =\n <T>(annotationId: symbol, noDefault = true) =>\n (node: AST.AST): T | undefined => {\n // Title fallback seems to be the identifier.\n const id = pipe(AST.getIdentifierAnnotation(node), Option.getOrUndefined);\n const value = pipe(AST.getAnnotation<T>(annotationId)(node), Option.getOrUndefined);\n if (noDefault && (value === defaultAnnotations[node._tag]?.annotations[annotationId] || value === id)) {\n return undefined;\n }\n\n return value;\n };\n\n/**\n * Recursively descend into AST to find first matching annotations.\n * Optionally skips default annotations for basic types (e.g., 'a string').\n */\n// TODO(burdon): Convert to effect pattern (i.e., return operator like getAnnotation).\nexport const findAnnotation = <T>(node: AST.AST, annotationId: symbol, noDefault = true): T | undefined => {\n const getAnnotationById = getAnnotation(annotationId, noDefault);\n\n const getBaseAnnotation = (node: AST.AST): T | undefined => {\n const value = getAnnotationById(node);\n if (value !== undefined) {\n return value as T;\n }\n\n if (AST.isUnion(node)) {\n if (isOption(node)) {\n return getAnnotationById(node.types[0]) as T;\n }\n }\n };\n\n return getBaseAnnotation(node);\n};\n\n//\n// Unions\n//\n\n/**\n * Effect S.optional creates a union type with undefined as the second type.\n */\nexport const isOption = (node: AST.AST): boolean => {\n return AST.isUnion(node) && node.types.length === 2 && AST.isUndefinedKeyword(node.types[1]);\n};\n\n/**\n * Determines if the node is a union of literal types.\n */\nexport const isLiteralUnion = (node: AST.AST): boolean => {\n return AST.isUnion(node) && node.types.every(AST.isLiteral);\n};\n\n/**\n * Determines if the node is a discriminated union.\n */\nexport const isDiscriminatedUnion = (node: AST.AST): boolean => {\n return AST.isUnion(node) && !!getDiscriminatingProps(node)?.length;\n};\n\n/**\n * Get the discriminating properties for the given union type.\n */\nexport const getDiscriminatingProps = (node: AST.AST): string[] | undefined => {\n invariant(AST.isUnion(node));\n if (isOption(node)) {\n return;\n }\n\n // Get common literals across all types.\n return node.types.reduce<string[]>((shared, type) => {\n const props = AST.getPropertySignatures(type)\n // TODO(burdon): Should check each literal is unique.\n .filter((p) => AST.isLiteral(p.type))\n .map((p) => p.name.toString());\n\n // Return common literals.\n return shared.length === 0 ? props : shared.filter((prop) => props.includes(prop));\n }, []);\n};\n\n/**\n * Get the discriminated type for the given value.\n */\nexport const getDiscriminatedType = (node: AST.AST, value: Record<string, any> = {}): AST.AST | undefined => {\n invariant(AST.isUnion(node));\n invariant(value);\n const props = getDiscriminatingProps(node);\n if (!props?.length) {\n return;\n }\n\n // Match provided values.\n for (const type of node.types) {\n const match = AST.getPropertySignatures(type)\n .filter((prop) => props?.includes(prop.name.toString()))\n .every((prop) => {\n invariant(AST.isLiteral(prop.type));\n return prop.type.literal === value[prop.name.toString()];\n });\n\n if (match) {\n return type;\n }\n }\n\n // Create union of discriminating properties.\n // NOTE: This may not work with non-overlapping variants.\n // TODO(burdon): Iterate through props and knock-out variants that don't match.\n const fields = Object.fromEntries(\n props\n .map((prop) => {\n const literals = node.types\n .map((type) => {\n const literal = AST.getPropertySignatures(type).find((p) => p.name.toString() === prop)!;\n invariant(AST.isLiteral(literal.type));\n return literal.type.literal;\n })\n .filter(nonNullable);\n\n return literals.length ? [prop, S.Literal(...literals)] : undefined;\n })\n .filter(nonNullable),\n );\n\n const schema = S.Struct(fields);\n return schema.ast;\n};\n\n/**\n * Maps AST nodes.\n * The user is responsible for recursively calling {@link mapAst} on the AST.\n * NOTE: Will evaluate suspended ASTs.\n */\nexport const mapAst = (ast: AST.AST, f: (ast: AST.AST) => AST.AST): AST.AST => {\n switch (ast._tag) {\n case 'TypeLiteral':\n return new AST.TypeLiteral(\n ast.propertySignatures.map(\n (prop) =>\n new AST.PropertySignature(prop.name, f(prop.type), prop.isOptional, prop.isReadonly, prop.annotations),\n ),\n ast.indexSignatures,\n );\n case 'Union':\n return AST.Union.make(ast.types.map(f), ast.annotations);\n case 'TupleType':\n return new AST.TupleType(\n ast.elements.map((t) => new AST.OptionalType(f(t.type), t.isOptional, t.annotations)),\n ast.rest.map((t) => new AST.Type(f(t.type), t.annotations)),\n ast.isReadonly,\n ast.annotations,\n );\n case 'Suspend': {\n const newAst = f(ast.f());\n return new AST.Suspend(() => newAst, ast.annotations);\n }\n default:\n // TODO(dmaretskyi): Support more nodes.\n return ast;\n }\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { AST, type Schema as S } from '@effect/schema';\nimport { Option, pipe } from 'effect';\n\nimport { decamelize } from '@dxos/util';\n\nconst ParamKeyAnnotationId = Symbol.for('@dxos/schema/annotation/ParamKey');\n\ntype ParamKeyAnnotationValue = { key: string };\n\nexport const getParamKeyAnnotation: (annotated: AST.Annotated) => Option.Option<ParamKeyAnnotationValue> =\n AST.getAnnotation<ParamKeyAnnotationValue>(ParamKeyAnnotationId);\n\nexport const ParamKeyAnnotation =\n (value: ParamKeyAnnotationValue) =>\n <S extends S.Annotable.All>(self: S): S.Annotable.Self<S> =>\n self.annotations({ [ParamKeyAnnotationId]: value });\n\n/**\n * HTTP params parser.\n * Supports custom key serialization.\n */\nexport class UrlParser<T extends Record<string, any>> {\n constructor(private readonly _schema: S.Struct<T>) {}\n\n /**\n * Parse URL params.\n */\n parse(_url: string): T {\n const url = new URL(_url);\n return Object.entries(this._schema.fields).reduce<Record<string, any>>((params, [key, type]) => {\n let value = url.searchParams.get(decamelize(key));\n if (value == null) {\n value = url.searchParams.get(key);\n }\n\n if (value != null) {\n if (AST.isNumberKeyword(type.ast)) {\n params[key] = parseInt(value);\n } else if (AST.isBooleanKeyword(type.ast)) {\n params[key] = value === 'true' || value === '1';\n } else {\n params[key] = value;\n }\n }\n\n return params;\n }, {}) as T;\n }\n\n /**\n * Return URL with encoded params.\n */\n create(_url: string, params: T): URL {\n const url = new URL(_url);\n Object.entries(params).forEach(([key, value]) => {\n if (value !== undefined) {\n const field = this._schema.fields[key];\n if (field) {\n const { key: serializedKey } = pipe(\n getParamKeyAnnotation(field.ast),\n Option.getOrElse(() => ({\n key: decamelize(key),\n })),\n );\n\n url.searchParams.set(serializedKey, String(value));\n }\n }\n });\n\n return url;\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,oBAA6C;ACA7C,IAAAA,iBAAiC;AACjC,oBAA6B;AAE7B,uBAA0B;AAC1B,kBAA4B;ACJ5B,IAAAA,iBAAsC;AACtC,IAAAC,iBAA6B;AAE7B,IAAAC,eAA2B;;ADepB,IAAMC,gBAAgB,CAACC,SAAAA;AAC5B,MAAIC,mBAAIC,gBAAgBF,IAAAA,KAASC,mBAAIE,cAAcH,IAAAA,KAASI,qBAAqBJ,IAAAA,GAAO;AACtF,WAAO;EACT;AAEA,MAAIC,mBAAII,gBAAgBL,IAAAA,GAAO;AAC7B,WAAO;EACT;AACA,MAAIC,mBAAIK,gBAAgBN,IAAAA,GAAO;AAC7B,WAAO;EACT;AACA,MAAIC,mBAAIM,iBAAiBP,IAAAA,GAAO;AAC9B,WAAO;EACT;AAEA,MAAIC,mBAAIO,QAAQR,IAAAA,GAAO;AACrB,WAAO;EACT;AAEA,MAAIC,mBAAIQ,UAAUT,IAAAA,GAAO;AACvB,WAAO;EACT;AACF;AAEO,IAAMU,eAAe,CAACV,SAA2B,CAAC,CAACD,cAAcC,IAAAA;;UAEvDW,aAAAA;AAIdA,cACYC,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,SAAS;AACP,cAAM,IAAIC,MAAM,uCAAuCD,IAAAA,EAAM;MAC/D;IACF;EACF;AACF,GAxBiBF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IAAIF,eAAeG,OAAOrE,KAAAA,CAAAA;QAC7C;MACF;IACF,CAAA;AAEA,WAAOuD;EACT;AACF;",
6
- "names": ["import_schema", "import_effect", "import_util", "getSimpleType", "node", "AST", "isObjectKeyword", "isTypeLiteral", "isDiscriminatedUnion", "isStringKeyword", "isNumberKeyword", "isBooleanKeyword", "isEnums", "isLiteral", "isSimpleType", "SimpleType", "getDefaultValue", "type", "Error", "PATH_REGEX", "PROP_REGEX", "JsonPath", "S", "NonEmptyString", "pipe", "pattern", "JsonProp", "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", "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", "nonNullable", "Literal", "Struct", "mapAst", "f", "TypeLiteral", "propertySignatures", "PropertySignature", "isOptional", "isReadonly", "indexSignatures", "Union", "make", "TupleType", "t", "OptionalType", "Type", "newAst", "Suspend", "ParamKeyAnnotationId", "Symbol", "for", "getParamKeyAnnotation", "ParamKeyAnnotation", "self", "UrlParser", "constructor", "_schema", "parse", "_url", "url", "URL", "params", "key", "searchParams", "get", "decamelize", "parseInt", "create", "forEach", "field", "serializedKey", "getOrElse", "set", "String"]
4
+ "sourcesContent": ["//\n// Copyright 2020 DXOS.org\n//\n\nimport { AST, JSONSchema, Schema as S } from '@effect/schema';\nimport type * as Types from 'effect/Types';\n\n// TODO(dmaretskyi): Remove re-exports.\nexport { AST, JSONSchema, S, Types };\n\nexport * from './ast';\nexport * from './url';\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { AST, Schema as S } from '@effect/schema';\nimport { Option, pipe } from 'effect';\n\nimport { invariant } from '@dxos/invariant';\nimport { nonNullable } from '@dxos/util';\n\n//\n// Refs\n// https://effect.website/docs/schema/introduction\n// https://www.npmjs.com/package/@effect/schema\n// https://effect-ts.github.io/effect/schema/AST.ts.html\n//\n\nexport type SimpleType = 'object' | 'string' | 'number' | 'boolean' | 'enum' | 'literal';\n\n/**\n * Get the base type; e.g., traverse through refinements.\n */\nexport const getSimpleType = (node: AST.AST): SimpleType | undefined => {\n if (AST.isObjectKeyword(node) || AST.isTypeLiteral(node) || isDiscriminatedUnion(node) || AST.isDeclaration(node)) {\n return 'object';\n }\n\n if (AST.isStringKeyword(node)) {\n return 'string';\n }\n if (AST.isNumberKeyword(node)) {\n return 'number';\n }\n if (AST.isBooleanKeyword(node)) {\n return 'boolean';\n }\n\n if (AST.isEnums(node)) {\n return 'enum';\n }\n\n if (AST.isLiteral(node)) {\n return 'literal';\n }\n};\n\nexport const isSimpleType = (node: AST.AST): boolean => !!getSimpleType(node);\n\nexport namespace SimpleType {\n /**\n * Returns the default empty value for a given SimpleType.\n * Used for initializing new array values etc.\n */\n export const getDefaultValue = (type: SimpleType): any => {\n switch (type) {\n case 'string': {\n return '';\n }\n case 'number': {\n return 0;\n }\n case 'boolean': {\n return false;\n }\n case 'object': {\n return {};\n }\n default: {\n throw new Error(`Unsupported type for default value: ${type}`);\n }\n }\n };\n}\n\n//\n// Branded types\n//\n\nexport type JsonProp = string & { __JsonPath: true; __JsonProp: true };\nexport type JsonPath = string & { __JsonPath: true };\n\nconst PATH_REGEX = /^[a-zA-Z_$][\\w$]*(?:\\.[a-zA-Z_$][\\w$]*|\\[\\d+\\])*$/;\nconst PROP_REGEX = /\\w+/;\n\n/**\n * https://www.ietf.org/archive/id/draft-goessner-dispatch-jsonpath-00.html\n */\nexport const JsonPath = S.NonEmptyString.pipe(S.pattern(PATH_REGEX)) as any as S.Schema<JsonPath>;\nexport const JsonProp = S.NonEmptyString.pipe(S.pattern(PROP_REGEX)) as any as S.Schema<JsonProp>;\n\nexport enum VisitResult {\n CONTINUE = 0,\n /**\n * Skip visiting children.\n */\n SKIP = 1,\n /**\n * Stop traversing immediately.\n */\n EXIT = 2,\n}\n\nexport type Path = (string | number)[];\n\nexport type TestFn = (node: AST.AST, path: Path, depth: number) => VisitResult | boolean | undefined;\n\nexport type VisitorFn = (node: AST.AST, path: Path, depth: number) => void;\n\nconst defaultTest: TestFn = isSimpleType;\n\n/**\n * Visit leaf nodes.\n * Refs:\n * - https://github.com/syntax-tree/unist-util-visit?tab=readme-ov-file#visitor\n * - https://github.com/syntax-tree/unist-util-is?tab=readme-ov-file#test\n */\nexport const visit: {\n (node: AST.AST, visitor: VisitorFn): void;\n (node: AST.AST, test: TestFn, visitor: VisitorFn): void;\n} = (node: AST.AST, testOrVisitor: TestFn | VisitorFn, visitor?: VisitorFn): void => {\n if (!visitor) {\n visitNode(node, defaultTest, testOrVisitor);\n } else {\n visitNode(node, testOrVisitor as TestFn, visitor);\n }\n};\n\nconst visitNode = (\n node: AST.AST,\n test: TestFn | undefined,\n visitor: VisitorFn,\n path: Path = [],\n depth = 0,\n): VisitResult | undefined => {\n const _result = test?.(node, path, depth);\n const result: VisitResult =\n _result === undefined\n ? VisitResult.CONTINUE\n : typeof _result === 'boolean'\n ? _result\n ? VisitResult.CONTINUE\n : VisitResult.SKIP\n : _result;\n\n if (result === VisitResult.EXIT) {\n return result;\n }\n if (result !== VisitResult.SKIP) {\n visitor(node, path, depth);\n }\n\n // Object.\n if (AST.isTypeLiteral(node)) {\n for (const prop of AST.getPropertySignatures(node)) {\n const currentPath = [...path, prop.name.toString()];\n const result = visitNode(prop.type, test, visitor, currentPath, depth + 1);\n if (result === VisitResult.EXIT) {\n return result;\n }\n }\n }\n\n // Array.\n else if (AST.isTupleType(node)) {\n for (const [i, element] of node.elements.entries()) {\n const currentPath = [...path, i];\n const result = visitNode(element.type, test, visitor, currentPath, depth);\n if (result === VisitResult.EXIT) {\n return result;\n }\n }\n }\n\n // Branching union (e.g., optional, discriminated unions).\n else if (AST.isUnion(node)) {\n for (const type of node.types) {\n const result = visitNode(type, test, visitor, path, depth);\n if (result === VisitResult.EXIT) {\n return result;\n }\n }\n }\n\n // Refinement.\n else if (AST.isRefinement(node)) {\n const result = visitNode(node.from, test, visitor, path, depth);\n if (result === VisitResult.EXIT) {\n return result;\n }\n }\n\n // TODO(burdon): Transforms?\n};\n\n/**\n * Recursively descend into AST to find first node that passes the test.\n */\n// TODO(burdon): Rewrite using visitNode?\nexport const findNode = (node: AST.AST, test: (node: AST.AST) => boolean): AST.AST | undefined => {\n if (test(node)) {\n return node;\n }\n\n // Object.\n else if (AST.isTypeLiteral(node)) {\n for (const prop of AST.getPropertySignatures(node)) {\n const child = findNode(prop.type, test);\n if (child) {\n return child;\n }\n }\n }\n\n // Tuple.\n else if (AST.isTupleType(node)) {\n for (const [_, element] of node.elements.entries()) {\n const child = findNode(element.type, test);\n if (child) {\n return child;\n }\n }\n }\n\n // Branching union (e.g., optional, discriminated unions).\n else if (AST.isUnion(node)) {\n if (isOption(node)) {\n for (const type of node.types) {\n const child = findNode(type, test);\n if (child) {\n return child;\n }\n }\n }\n }\n\n // Refinement.\n else if (AST.isRefinement(node)) {\n return findNode(node.from, test);\n }\n};\n\n/**\n * Get the AST node for the given property (dot-path).\n */\nexport const findProperty = (schema: S.Schema<any>, path: JsonPath | JsonProp): AST.AST | undefined => {\n const getProp = (node: AST.AST, path: JsonProp[]): AST.AST | undefined => {\n const [name, ...rest] = path;\n const typeNode = findNode(node, AST.isTypeLiteral);\n invariant(typeNode);\n for (const prop of AST.getPropertySignatures(typeNode)) {\n if (prop.name === name) {\n if (rest.length) {\n return getProp(prop.type, rest);\n } else {\n return prop.type;\n }\n }\n }\n };\n\n return getProp(schema.ast, path.split('.') as JsonProp[]);\n};\n\n//\n// Annotations\n//\n\nconst defaultAnnotations: Record<string, AST.Annotated> = {\n ['ObjectKeyword' as const]: AST.objectKeyword,\n ['StringKeyword' as const]: AST.stringKeyword,\n ['NumberKeyword' as const]: AST.numberKeyword,\n ['BooleanKeyword' as const]: AST.booleanKeyword,\n};\n\n/**\n * Get annotation or return undefined.\n * @param annotationId\n * @param noDefault If true, then return undefined for effect library defined values.\n */\nexport const getAnnotation =\n <T>(annotationId: symbol, noDefault = true) =>\n (node: AST.AST): T | undefined => {\n // Title fallback seems to be the identifier.\n const id = pipe(AST.getIdentifierAnnotation(node), Option.getOrUndefined);\n const value = pipe(AST.getAnnotation<T>(annotationId)(node), Option.getOrUndefined);\n if (noDefault && (value === defaultAnnotations[node._tag]?.annotations[annotationId] || value === id)) {\n return undefined;\n }\n\n return value;\n };\n\n/**\n * Recursively descend into AST to find first matching annotations.\n * Optionally skips default annotations for basic types (e.g., 'a string').\n */\n// TODO(burdon): Convert to effect pattern (i.e., return operator like getAnnotation).\nexport const findAnnotation = <T>(node: AST.AST, annotationId: symbol, noDefault = true): T | undefined => {\n const getAnnotationById = getAnnotation(annotationId, noDefault);\n\n const getBaseAnnotation = (node: AST.AST): T | undefined => {\n const value = getAnnotationById(node);\n if (value !== undefined) {\n return value as T;\n }\n\n if (AST.isUnion(node)) {\n if (isOption(node)) {\n return getAnnotationById(node.types[0]) as T;\n }\n }\n };\n\n return getBaseAnnotation(node);\n};\n\n//\n// Unions\n//\n\n/**\n * Effect S.optional creates a union type with undefined as the second type.\n */\nexport const isOption = (node: AST.AST): boolean => {\n return AST.isUnion(node) && node.types.length === 2 && AST.isUndefinedKeyword(node.types[1]);\n};\n\n/**\n * Determines if the node is a union of literal types.\n */\nexport const isLiteralUnion = (node: AST.AST): boolean => {\n return AST.isUnion(node) && node.types.every(AST.isLiteral);\n};\n\n/**\n * Determines if the node is a discriminated union.\n */\nexport const isDiscriminatedUnion = (node: AST.AST): boolean => {\n return AST.isUnion(node) && !!getDiscriminatingProps(node)?.length;\n};\n\n/**\n * Get the discriminating properties for the given union type.\n */\nexport const getDiscriminatingProps = (node: AST.AST): string[] | undefined => {\n invariant(AST.isUnion(node));\n if (isOption(node)) {\n return;\n }\n\n // Get common literals across all types.\n return node.types.reduce<string[]>((shared, type) => {\n const props = AST.getPropertySignatures(type)\n // TODO(burdon): Should check each literal is unique.\n .filter((p) => AST.isLiteral(p.type))\n .map((p) => p.name.toString());\n\n // Return common literals.\n return shared.length === 0 ? props : shared.filter((prop) => props.includes(prop));\n }, []);\n};\n\n/**\n * Get the discriminated type for the given value.\n */\nexport const getDiscriminatedType = (node: AST.AST, value: Record<string, any> = {}): AST.AST | undefined => {\n invariant(AST.isUnion(node));\n invariant(value);\n const props = getDiscriminatingProps(node);\n if (!props?.length) {\n return;\n }\n\n // Match provided values.\n for (const type of node.types) {\n const match = AST.getPropertySignatures(type)\n .filter((prop) => props?.includes(prop.name.toString()))\n .every((prop) => {\n invariant(AST.isLiteral(prop.type));\n return prop.type.literal === value[prop.name.toString()];\n });\n\n if (match) {\n return type;\n }\n }\n\n // Create union of discriminating properties.\n // NOTE: This may not work with non-overlapping variants.\n // TODO(burdon): Iterate through props and knock-out variants that don't match.\n const fields = Object.fromEntries(\n props\n .map((prop) => {\n const literals = node.types\n .map((type) => {\n const literal = AST.getPropertySignatures(type).find((p) => p.name.toString() === prop)!;\n invariant(AST.isLiteral(literal.type));\n return literal.type.literal;\n })\n .filter(nonNullable);\n\n return literals.length ? [prop, S.Literal(...literals)] : undefined;\n })\n .filter(nonNullable),\n );\n\n const schema = S.Struct(fields);\n return schema.ast;\n};\n\n/**\n * Maps AST nodes.\n * The user is responsible for recursively calling {@link mapAst} on the AST.\n * NOTE: Will evaluate suspended ASTs.\n */\nexport const mapAst = (ast: AST.AST, f: (ast: AST.AST, key: keyof any | undefined) => AST.AST): AST.AST => {\n switch (ast._tag) {\n case 'TypeLiteral':\n return new AST.TypeLiteral(\n ast.propertySignatures.map(\n (prop) =>\n new AST.PropertySignature(\n prop.name,\n f(prop.type, prop.name),\n prop.isOptional,\n prop.isReadonly,\n prop.annotations,\n ),\n ),\n ast.indexSignatures,\n );\n case 'Union':\n return AST.Union.make(ast.types.map(f), ast.annotations);\n case 'TupleType':\n return new AST.TupleType(\n ast.elements.map((t, index) => new AST.OptionalType(f(t.type, index), t.isOptional, t.annotations)),\n ast.rest.map((t) => new AST.Type(f(t.type, undefined), t.annotations)),\n ast.isReadonly,\n ast.annotations,\n );\n case 'Suspend': {\n const newAst = f(ast.f(), undefined);\n return new AST.Suspend(() => newAst, ast.annotations);\n }\n default:\n // TODO(dmaretskyi): Support more nodes.\n return ast;\n }\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { AST, type Schema as S } from '@effect/schema';\nimport { Option, pipe } from 'effect';\n\nimport { decamelize } from '@dxos/util';\n\nconst ParamKeyAnnotationId = Symbol.for('@dxos/schema/annotation/ParamKey');\n\ntype ParamKeyAnnotationValue = { key: string };\n\nexport const getParamKeyAnnotation: (annotated: AST.Annotated) => Option.Option<ParamKeyAnnotationValue> =\n AST.getAnnotation<ParamKeyAnnotationValue>(ParamKeyAnnotationId);\n\nexport const ParamKeyAnnotation =\n (value: ParamKeyAnnotationValue) =>\n <S extends S.Annotable.All>(self: S): S.Annotable.Self<S> =>\n self.annotations({ [ParamKeyAnnotationId]: value });\n\n/**\n * HTTP params parser.\n * Supports custom key serialization.\n */\nexport class UrlParser<T extends Record<string, any>> {\n constructor(private readonly _schema: S.Struct<T>) {}\n\n /**\n * Parse URL params.\n */\n parse(_url: string): T {\n const url = new URL(_url);\n return Object.entries(this._schema.fields).reduce<Record<string, any>>((params, [key, type]) => {\n let value = url.searchParams.get(decamelize(key));\n if (value == null) {\n value = url.searchParams.get(key);\n }\n\n if (value != null) {\n if (AST.isNumberKeyword(type.ast)) {\n params[key] = parseInt(value);\n } else if (AST.isBooleanKeyword(type.ast)) {\n params[key] = value === 'true' || value === '1';\n } else {\n params[key] = value;\n }\n }\n\n return params;\n }, {}) as T;\n }\n\n /**\n * Return URL with encoded params.\n */\n create(_url: string, params: T): URL {\n const url = new URL(_url);\n Object.entries(params).forEach(([key, value]) => {\n if (value !== undefined) {\n const field = this._schema.fields[key];\n if (field) {\n const { key: serializedKey } = pipe(\n getParamKeyAnnotation(field.ast),\n Option.getOrElse(() => ({\n key: decamelize(key),\n })),\n );\n\n url.searchParams.set(serializedKey, String(value));\n }\n }\n });\n\n return url;\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,oBAA6C;ACA7C,IAAAA,iBAAiC;AACjC,oBAA6B;AAE7B,uBAA0B;AAC1B,kBAA4B;ACJ5B,IAAAA,iBAAsC;AACtC,IAAAC,iBAA6B;AAE7B,IAAAC,eAA2B;;ADepB,IAAMC,gBAAgB,CAACC,SAAAA;AAC5B,MAAIC,mBAAIC,gBAAgBF,IAAAA,KAASC,mBAAIE,cAAcH,IAAAA,KAASI,qBAAqBJ,IAAAA,KAASC,mBAAII,cAAcL,IAAAA,GAAO;AACjH,WAAO;EACT;AAEA,MAAIC,mBAAIK,gBAAgBN,IAAAA,GAAO;AAC7B,WAAO;EACT;AACA,MAAIC,mBAAIM,gBAAgBP,IAAAA,GAAO;AAC7B,WAAO;EACT;AACA,MAAIC,mBAAIO,iBAAiBR,IAAAA,GAAO;AAC9B,WAAO;EACT;AAEA,MAAIC,mBAAIQ,QAAQT,IAAAA,GAAO;AACrB,WAAO;EACT;AAEA,MAAIC,mBAAIS,UAAUV,IAAAA,GAAO;AACvB,WAAO;EACT;AACF;AAEO,IAAMW,eAAe,CAACX,SAA2B,CAAC,CAACD,cAAcC,IAAAA;;UAEvDY,aAAAA;AAIdA,cACYC,kBAAkB,CAACC,SAAAA;AAC9B,YAAQA,MAAAA;MACN,KAAK,UAAU;AACb,eAAO;MACT;MACA,KAAK,UAAU;AACb,eAAO;MACT;M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,YAAIO,OAAO;AACT,gBAAM,EAAEP,KAAKQ,cAAa,QAAKzH,eAAAA,MAC7BsG,sBAAsBkB,MAAMhF,GAAG,GAC/BY,eAAAA,OAAOsE,UAAU,OAAO;YACtBT,SAAKG,yBAAWH,GAAAA;UAClB,EAAA,CAAA;AAGFH,cAAII,aAAaS,IAAIF,eAAeG,OAAOtE,KAAAA,CAAAA;QAC7C;MACF;IACF,CAAA;AAEA,WAAOwD;EACT;AACF;",
6
+ "names": ["import_schema", "import_effect", "import_util", "getSimpleType", "node", "AST", "isObjectKeyword", "isTypeLiteral", "isDiscriminatedUnion", "isDeclaration", "isStringKeyword", "isNumberKeyword", "isBooleanKeyword", "isEnums", "isLiteral", "isSimpleType", "SimpleType", "getDefaultValue", "type", "Error", "PATH_REGEX", "PROP_REGEX", "JsonPath", "S", "NonEmptyString", "pipe", "pattern", "JsonProp", "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", "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", "nonNullable", "Literal", "Struct", "mapAst", "f", "TypeLiteral", "propertySignatures", "PropertySignature", "isOptional", "isReadonly", "indexSignatures", "Union", "make", "TupleType", "t", "index", "OptionalType", "Type", "newAst", "Suspend", "ParamKeyAnnotationId", "Symbol", "for", "getParamKeyAnnotation", "ParamKeyAnnotation", "self", "UrlParser", "constructor", "_schema", "parse", "_url", "url", "URL", "params", "key", "searchParams", "get", "decamelize", "parseInt", "create", "forEach", "field", "serializedKey", "getOrElse", "set", "String"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"packages/common/effect/src/ast.ts":{"bytes":41444,"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/effect/src/url.ts":{"bytes":7711,"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/effect/src/index.ts":{"bytes":1150,"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"packages/common/effect/src/ast.ts","kind":"import-statement","original":"./ast"},{"path":"packages/common/effect/src/url.ts","kind":"import-statement","original":"./url"}],"format":"esm"}},"outputs":{"packages/common/effect/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":25491},"packages/common/effect/dist/lib/node/index.cjs":{"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["AST","JSONSchema","JsonPath","JsonProp","ParamKeyAnnotation","S","SimpleType","UrlParser","VisitResult","findAnnotation","findNode","findProperty","getAnnotation","getDiscriminatedType","getDiscriminatingProps","getParamKeyAnnotation","getSimpleType","isDiscriminatedUnion","isLiteralUnion","isOption","isSimpleType","mapAst","visit"],"entryPoint":"packages/common/effect/src/index.ts","inputs":{"packages/common/effect/src/index.ts":{"bytesInOutput":72},"packages/common/effect/src/ast.ts":{"bytesInOutput":8647},"packages/common/effect/src/url.ts":{"bytesInOutput":1624}},"bytes":10876}}}
1
+ {"inputs":{"packages/common/effect/src/ast.ts":{"bytes":41924,"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/effect/src/url.ts":{"bytes":7711,"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/effect/src/index.ts":{"bytes":1150,"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"packages/common/effect/src/ast.ts","kind":"import-statement","original":"./ast"},{"path":"packages/common/effect/src/url.ts","kind":"import-statement","original":"./url"}],"format":"esm"}},"outputs":{"packages/common/effect/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":25789},"packages/common/effect/dist/lib/node/index.cjs":{"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["AST","JSONSchema","JsonPath","JsonProp","ParamKeyAnnotation","S","SimpleType","UrlParser","VisitResult","findAnnotation","findNode","findProperty","getAnnotation","getDiscriminatedType","getDiscriminatingProps","getParamKeyAnnotation","getSimpleType","isDiscriminatedUnion","isLiteralUnion","isOption","isSimpleType","mapAst","visit"],"entryPoint":"packages/common/effect/src/index.ts","inputs":{"packages/common/effect/src/index.ts":{"bytesInOutput":72},"packages/common/effect/src/ast.ts":{"bytesInOutput":8725},"packages/common/effect/src/url.ts":{"bytesInOutput":1624}},"bytes":10954}}}
@@ -10,7 +10,7 @@ import { invariant } from "@dxos/invariant";
10
10
  import { nonNullable } from "@dxos/util";
11
11
  var __dxlog_file = "/home/runner/work/dxos/dxos/packages/common/effect/src/ast.ts";
12
12
  var getSimpleType = (node) => {
13
- if (AST.isObjectKeyword(node) || AST.isTypeLiteral(node) || isDiscriminatedUnion(node)) {
13
+ if (AST.isObjectKeyword(node) || AST.isTypeLiteral(node) || isDiscriminatedUnion(node) || AST.isDeclaration(node)) {
14
14
  return "object";
15
15
  }
16
16
  if (AST.isStringKeyword(node)) {
@@ -52,7 +52,7 @@ var SimpleType;
52
52
  }
53
53
  };
54
54
  })(SimpleType || (SimpleType = {}));
55
- var PATH_REGEX = /[a-zA-Z_$][\w$]*(?:\.[a-zA-Z_$][\w$]*)*/;
55
+ var PATH_REGEX = /^[a-zA-Z_$][\w$]*(?:\.[a-zA-Z_$][\w$]*|\[\d+\])*$/;
56
56
  var PROP_REGEX = /\w+/;
57
57
  var JsonPath = S.NonEmptyString.pipe(S.pattern(PATH_REGEX));
58
58
  var JsonProp = S.NonEmptyString.pipe(S.pattern(PROP_REGEX));
@@ -291,13 +291,13 @@ var getDiscriminatedType = (node, value = {}) => {
291
291
  var mapAst = (ast, f) => {
292
292
  switch (ast._tag) {
293
293
  case "TypeLiteral":
294
- return new AST.TypeLiteral(ast.propertySignatures.map((prop) => new AST.PropertySignature(prop.name, f(prop.type), prop.isOptional, prop.isReadonly, prop.annotations)), ast.indexSignatures);
294
+ return new AST.TypeLiteral(ast.propertySignatures.map((prop) => new AST.PropertySignature(prop.name, f(prop.type, prop.name), prop.isOptional, prop.isReadonly, prop.annotations)), ast.indexSignatures);
295
295
  case "Union":
296
296
  return AST.Union.make(ast.types.map(f), ast.annotations);
297
297
  case "TupleType":
298
- return new AST.TupleType(ast.elements.map((t) => new AST.OptionalType(f(t.type), t.isOptional, t.annotations)), ast.rest.map((t) => new AST.Type(f(t.type), t.annotations)), ast.isReadonly, ast.annotations);
298
+ return new AST.TupleType(ast.elements.map((t, index) => new AST.OptionalType(f(t.type, index), t.isOptional, t.annotations)), ast.rest.map((t) => new AST.Type(f(t.type, void 0), t.annotations)), ast.isReadonly, ast.annotations);
299
299
  case "Suspend": {
300
- const newAst = f(ast.f());
300
+ const newAst = f(ast.f(), void 0);
301
301
  return new AST.Suspend(() => newAst, ast.annotations);
302
302
  }
303
303
  default:
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/index.ts", "../../../src/ast.ts", "../../../src/url.ts"],
4
- "sourcesContent": ["//\n// Copyright 2020 DXOS.org\n//\n\nimport { AST, JSONSchema, Schema as S } from '@effect/schema';\nimport type * as Types from 'effect/Types';\n\n// TODO(dmaretskyi): Remove re-exports.\nexport { AST, JSONSchema, S, Types };\n\nexport * from './ast';\nexport * from './url';\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { AST, Schema as S } from '@effect/schema';\nimport { Option, pipe } from 'effect';\n\nimport { invariant } from '@dxos/invariant';\nimport { nonNullable } from '@dxos/util';\n\n//\n// Refs\n// https://effect.website/docs/schema/introduction\n// https://www.npmjs.com/package/@effect/schema\n// https://effect-ts.github.io/effect/schema/AST.ts.html\n//\n\nexport type SimpleType = 'object' | 'string' | 'number' | 'boolean' | 'enum' | 'literal';\n\n/**\n * Get the base type; e.g., traverse through refinements.\n */\nexport const getSimpleType = (node: AST.AST): SimpleType | undefined => {\n if (AST.isObjectKeyword(node) || AST.isTypeLiteral(node) || isDiscriminatedUnion(node)) {\n return 'object';\n }\n\n if (AST.isStringKeyword(node)) {\n return 'string';\n }\n if (AST.isNumberKeyword(node)) {\n return 'number';\n }\n if (AST.isBooleanKeyword(node)) {\n return 'boolean';\n }\n\n if (AST.isEnums(node)) {\n return 'enum';\n }\n\n if (AST.isLiteral(node)) {\n return 'literal';\n }\n};\n\nexport const isSimpleType = (node: AST.AST): boolean => !!getSimpleType(node);\n\nexport namespace SimpleType {\n /**\n * Returns the default empty value for a given SimpleType.\n * Used for initializing new array values etc.\n */\n export const getDefaultValue = (type: SimpleType): any => {\n switch (type) {\n case 'string': {\n return '';\n }\n case 'number': {\n return 0;\n }\n case 'boolean': {\n return false;\n }\n case 'object': {\n return {};\n }\n default: {\n throw new Error(`Unsupported type for default value: ${type}`);\n }\n }\n };\n}\n\n//\n// Branded types\n//\n\nexport 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$]*)*/;\nconst PROP_REGEX = /\\w+/;\n\n/**\n * https://www.ietf.org/archive/id/draft-goessner-dispatch-jsonpath-00.html\n */\nexport const JsonPath = S.NonEmptyString.pipe(S.pattern(PATH_REGEX)) as any as S.Schema<JsonPath>;\nexport const JsonProp = S.NonEmptyString.pipe(S.pattern(PROP_REGEX)) as any as S.Schema<JsonProp>;\n\nexport enum VisitResult {\n CONTINUE = 0,\n /**\n * Skip visiting children.\n */\n SKIP = 1,\n /**\n * Stop traversing immediately.\n */\n EXIT = 2,\n}\n\nexport type Path = (string | number)[];\n\nexport type TestFn = (node: AST.AST, path: Path, depth: number) => VisitResult | boolean | undefined;\n\nexport type VisitorFn = (node: AST.AST, path: Path, depth: number) => void;\n\nconst defaultTest: TestFn = isSimpleType;\n\n/**\n * Visit leaf nodes.\n * Refs:\n * - https://github.com/syntax-tree/unist-util-visit?tab=readme-ov-file#visitor\n * - https://github.com/syntax-tree/unist-util-is?tab=readme-ov-file#test\n */\nexport const visit: {\n (node: AST.AST, visitor: VisitorFn): void;\n (node: AST.AST, test: TestFn, visitor: VisitorFn): void;\n} = (node: AST.AST, testOrVisitor: TestFn | VisitorFn, visitor?: VisitorFn): void => {\n if (!visitor) {\n visitNode(node, defaultTest, testOrVisitor);\n } else {\n visitNode(node, testOrVisitor as TestFn, visitor);\n }\n};\n\nconst visitNode = (\n node: AST.AST,\n test: TestFn | undefined,\n visitor: VisitorFn,\n path: Path = [],\n depth = 0,\n): VisitResult | undefined => {\n const _result = test?.(node, path, depth);\n const result: VisitResult =\n _result === undefined\n ? VisitResult.CONTINUE\n : typeof _result === 'boolean'\n ? _result\n ? VisitResult.CONTINUE\n : VisitResult.SKIP\n : _result;\n\n if (result === VisitResult.EXIT) {\n return result;\n }\n if (result !== VisitResult.SKIP) {\n visitor(node, path, depth);\n }\n\n // Object.\n if (AST.isTypeLiteral(node)) {\n for (const prop of AST.getPropertySignatures(node)) {\n const currentPath = [...path, prop.name.toString()];\n const result = visitNode(prop.type, test, visitor, currentPath, depth + 1);\n if (result === VisitResult.EXIT) {\n return result;\n }\n }\n }\n\n // Array.\n else if (AST.isTupleType(node)) {\n for (const [i, element] of node.elements.entries()) {\n const currentPath = [...path, i];\n const result = visitNode(element.type, test, visitor, currentPath, depth);\n if (result === VisitResult.EXIT) {\n return result;\n }\n }\n }\n\n // Branching union (e.g., optional, discriminated unions).\n else if (AST.isUnion(node)) {\n for (const type of node.types) {\n const result = visitNode(type, test, visitor, path, depth);\n if (result === VisitResult.EXIT) {\n return result;\n }\n }\n }\n\n // Refinement.\n else if (AST.isRefinement(node)) {\n const result = visitNode(node.from, test, visitor, path, depth);\n if (result === VisitResult.EXIT) {\n return result;\n }\n }\n\n // TODO(burdon): Transforms?\n};\n\n/**\n * Recursively descend into AST to find first node that passes the test.\n */\n// TODO(burdon): Rewrite using visitNode?\nexport const findNode = (node: AST.AST, test: (node: AST.AST) => boolean): AST.AST | undefined => {\n if (test(node)) {\n return node;\n }\n\n // Object.\n else if (AST.isTypeLiteral(node)) {\n for (const prop of AST.getPropertySignatures(node)) {\n const child = findNode(prop.type, test);\n if (child) {\n return child;\n }\n }\n }\n\n // Tuple.\n else if (AST.isTupleType(node)) {\n for (const [_, element] of node.elements.entries()) {\n const child = findNode(element.type, test);\n if (child) {\n return child;\n }\n }\n }\n\n // Branching union (e.g., optional, discriminated unions).\n else if (AST.isUnion(node)) {\n if (isOption(node)) {\n for (const type of node.types) {\n const child = findNode(type, test);\n if (child) {\n return child;\n }\n }\n }\n }\n\n // Refinement.\n else if (AST.isRefinement(node)) {\n return findNode(node.from, test);\n }\n};\n\n/**\n * Get the AST node for the given property (dot-path).\n */\nexport const findProperty = (schema: S.Schema<any>, path: JsonPath | JsonProp): AST.AST | undefined => {\n const getProp = (node: AST.AST, path: JsonProp[]): AST.AST | undefined => {\n const [name, ...rest] = path;\n const typeNode = findNode(node, AST.isTypeLiteral);\n invariant(typeNode);\n for (const prop of AST.getPropertySignatures(typeNode)) {\n if (prop.name === name) {\n if (rest.length) {\n return getProp(prop.type, rest);\n } else {\n return prop.type;\n }\n }\n }\n };\n\n return getProp(schema.ast, path.split('.') as JsonProp[]);\n};\n\n//\n// Annotations\n//\n\nconst defaultAnnotations: Record<string, AST.Annotated> = {\n ['ObjectKeyword' as const]: AST.objectKeyword,\n ['StringKeyword' as const]: AST.stringKeyword,\n ['NumberKeyword' as const]: AST.numberKeyword,\n ['BooleanKeyword' as const]: AST.booleanKeyword,\n};\n\n/**\n * Get annotation or return undefined.\n * @param annotationId\n * @param noDefault If true, then return undefined for effect library defined values.\n */\nexport const getAnnotation =\n <T>(annotationId: symbol, noDefault = true) =>\n (node: AST.AST): T | undefined => {\n // Title fallback seems to be the identifier.\n const id = pipe(AST.getIdentifierAnnotation(node), Option.getOrUndefined);\n const value = pipe(AST.getAnnotation<T>(annotationId)(node), Option.getOrUndefined);\n if (noDefault && (value === defaultAnnotations[node._tag]?.annotations[annotationId] || value === id)) {\n return undefined;\n }\n\n return value;\n };\n\n/**\n * Recursively descend into AST to find first matching annotations.\n * Optionally skips default annotations for basic types (e.g., 'a string').\n */\n// TODO(burdon): Convert to effect pattern (i.e., return operator like getAnnotation).\nexport const findAnnotation = <T>(node: AST.AST, annotationId: symbol, noDefault = true): T | undefined => {\n const getAnnotationById = getAnnotation(annotationId, noDefault);\n\n const getBaseAnnotation = (node: AST.AST): T | undefined => {\n const value = getAnnotationById(node);\n if (value !== undefined) {\n return value as T;\n }\n\n if (AST.isUnion(node)) {\n if (isOption(node)) {\n return getAnnotationById(node.types[0]) as T;\n }\n }\n };\n\n return getBaseAnnotation(node);\n};\n\n//\n// Unions\n//\n\n/**\n * Effect S.optional creates a union type with undefined as the second type.\n */\nexport const isOption = (node: AST.AST): boolean => {\n return AST.isUnion(node) && node.types.length === 2 && AST.isUndefinedKeyword(node.types[1]);\n};\n\n/**\n * Determines if the node is a union of literal types.\n */\nexport const isLiteralUnion = (node: AST.AST): boolean => {\n return AST.isUnion(node) && node.types.every(AST.isLiteral);\n};\n\n/**\n * Determines if the node is a discriminated union.\n */\nexport const isDiscriminatedUnion = (node: AST.AST): boolean => {\n return AST.isUnion(node) && !!getDiscriminatingProps(node)?.length;\n};\n\n/**\n * Get the discriminating properties for the given union type.\n */\nexport const getDiscriminatingProps = (node: AST.AST): string[] | undefined => {\n invariant(AST.isUnion(node));\n if (isOption(node)) {\n return;\n }\n\n // Get common literals across all types.\n return node.types.reduce<string[]>((shared, type) => {\n const props = AST.getPropertySignatures(type)\n // TODO(burdon): Should check each literal is unique.\n .filter((p) => AST.isLiteral(p.type))\n .map((p) => p.name.toString());\n\n // Return common literals.\n return shared.length === 0 ? props : shared.filter((prop) => props.includes(prop));\n }, []);\n};\n\n/**\n * Get the discriminated type for the given value.\n */\nexport const getDiscriminatedType = (node: AST.AST, value: Record<string, any> = {}): AST.AST | undefined => {\n invariant(AST.isUnion(node));\n invariant(value);\n const props = getDiscriminatingProps(node);\n if (!props?.length) {\n return;\n }\n\n // Match provided values.\n for (const type of node.types) {\n const match = AST.getPropertySignatures(type)\n .filter((prop) => props?.includes(prop.name.toString()))\n .every((prop) => {\n invariant(AST.isLiteral(prop.type));\n return prop.type.literal === value[prop.name.toString()];\n });\n\n if (match) {\n return type;\n }\n }\n\n // Create union of discriminating properties.\n // NOTE: This may not work with non-overlapping variants.\n // TODO(burdon): Iterate through props and knock-out variants that don't match.\n const fields = Object.fromEntries(\n props\n .map((prop) => {\n const literals = node.types\n .map((type) => {\n const literal = AST.getPropertySignatures(type).find((p) => p.name.toString() === prop)!;\n invariant(AST.isLiteral(literal.type));\n return literal.type.literal;\n })\n .filter(nonNullable);\n\n return literals.length ? [prop, S.Literal(...literals)] : undefined;\n })\n .filter(nonNullable),\n );\n\n const schema = S.Struct(fields);\n return schema.ast;\n};\n\n/**\n * Maps AST nodes.\n * The user is responsible for recursively calling {@link mapAst} on the AST.\n * NOTE: Will evaluate suspended ASTs.\n */\nexport const mapAst = (ast: AST.AST, f: (ast: AST.AST) => AST.AST): AST.AST => {\n switch (ast._tag) {\n case 'TypeLiteral':\n return new AST.TypeLiteral(\n ast.propertySignatures.map(\n (prop) =>\n new AST.PropertySignature(prop.name, f(prop.type), prop.isOptional, prop.isReadonly, prop.annotations),\n ),\n ast.indexSignatures,\n );\n case 'Union':\n return AST.Union.make(ast.types.map(f), ast.annotations);\n case 'TupleType':\n return new AST.TupleType(\n ast.elements.map((t) => new AST.OptionalType(f(t.type), t.isOptional, t.annotations)),\n ast.rest.map((t) => new AST.Type(f(t.type), t.annotations)),\n ast.isReadonly,\n ast.annotations,\n );\n case 'Suspend': {\n const newAst = f(ast.f());\n return new AST.Suspend(() => newAst, ast.annotations);\n }\n default:\n // TODO(dmaretskyi): Support more nodes.\n return ast;\n }\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { AST, type Schema as S } from '@effect/schema';\nimport { Option, pipe } from 'effect';\n\nimport { decamelize } from '@dxos/util';\n\nconst ParamKeyAnnotationId = Symbol.for('@dxos/schema/annotation/ParamKey');\n\ntype ParamKeyAnnotationValue = { key: string };\n\nexport const getParamKeyAnnotation: (annotated: AST.Annotated) => Option.Option<ParamKeyAnnotationValue> =\n AST.getAnnotation<ParamKeyAnnotationValue>(ParamKeyAnnotationId);\n\nexport const ParamKeyAnnotation =\n (value: ParamKeyAnnotationValue) =>\n <S extends S.Annotable.All>(self: S): S.Annotable.Self<S> =>\n self.annotations({ [ParamKeyAnnotationId]: value });\n\n/**\n * HTTP params parser.\n * Supports custom key serialization.\n */\nexport class UrlParser<T extends Record<string, any>> {\n constructor(private readonly _schema: S.Struct<T>) {}\n\n /**\n * Parse URL params.\n */\n parse(_url: string): T {\n const url = new URL(_url);\n return Object.entries(this._schema.fields).reduce<Record<string, any>>((params, [key, type]) => {\n let value = url.searchParams.get(decamelize(key));\n if (value == null) {\n value = url.searchParams.get(key);\n }\n\n if (value != null) {\n if (AST.isNumberKeyword(type.ast)) {\n params[key] = parseInt(value);\n } else if (AST.isBooleanKeyword(type.ast)) {\n params[key] = value === 'true' || value === '1';\n } else {\n params[key] = value;\n }\n }\n\n return params;\n }, {}) as T;\n }\n\n /**\n * Return URL with encoded params.\n */\n create(_url: string, params: T): URL {\n const url = new URL(_url);\n Object.entries(params).forEach(([key, value]) => {\n if (value !== undefined) {\n const field = this._schema.fields[key];\n if (field) {\n const { key: serializedKey } = pipe(\n getParamKeyAnnotation(field.ast),\n Option.getOrElse(() => ({\n key: decamelize(key),\n })),\n );\n\n url.searchParams.set(serializedKey, String(value));\n }\n }\n });\n\n return url;\n }\n}\n"],
5
- "mappings": ";;;AAIA,SAASA,OAAAA,MAAKC,YAAYC,UAAUC,UAAS;;;ACA7C,SAASC,KAAKC,UAAUC,SAAS;AACjC,SAASC,QAAQC,YAAY;AAE7B,SAASC,iBAAiB;AAC1B,SAASC,mBAAmB;;AAcrB,IAAMC,gBAAgB,CAACC,SAAAA;AAC5B,MAAIR,IAAIS,gBAAgBD,IAAAA,KAASR,IAAIU,cAAcF,IAAAA,KAASG,qBAAqBH,IAAAA,GAAO;AACtF,WAAO;EACT;AAEA,MAAIR,IAAIY,gBAAgBJ,IAAAA,GAAO;AAC7B,WAAO;EACT;AACA,MAAIR,IAAIa,gBAAgBL,IAAAA,GAAO;AAC7B,WAAO;EACT;AACA,MAAIR,IAAIc,iBAAiBN,IAAAA,GAAO;AAC9B,WAAO;EACT;AAEA,MAAIR,IAAIe,QAAQP,IAAAA,GAAO;AACrB,WAA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AAAA;AACpBG,WAAOC,QAAQG,MAAAA,EAAQW,QAAQ,CAAC,CAACV,KAAKf,KAAAA,MAAM;AAC1C,UAAIA,UAAU0B,QAAW;AACvB,cAAMC,QAAQ,KAAKtB,QAAQO,OAAOG,GAAAA;AAClC,YAAIY,OAAO;AACT,gBAAM,EAAEZ,KAAKa,cAAa,IAAKC,MAC7BjC,sBAAsB+B,MAAMN,GAAG,GAC/BS,QAAOC,UAAU,OAAO;YACtBhB,KAAKI,WAAWJ,GAAAA;UAClB,EAAA,CAAA;AAGFP,cAAIS,aAAae,IAAIJ,eAAeK,OAAOjC,KAAAA,CAAAA;QAC7C;MACF;IACF,CAAA;AAEA,WAAOQ;EACT;AACF;",
6
- "names": ["AST", "JSONSchema", "Schema", "S", "AST", "Schema", "S", "Option", "pipe", "invariant", "nonNullable", "getSimpleType", "node", "isObjectKeyword", "isTypeLiteral", "isDiscriminatedUnion", "isStringKeyword", "isNumberKeyword", "isBooleanKeyword", "isEnums", "isLiteral", "isSimpleType", "SimpleType", "getDefaultValue", "type", "Error", "PATH_REGEX", "PROP_REGEX", "JsonPath", "NonEmptyString", "pattern", "JsonProp", "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", "OptionalType", "Type", "newAst", "Suspend", "AST", "Option", "pipe", "decamelize", "ParamKeyAnnotationId", "Symbol", "for", "getParamKeyAnnotation", "AST", "getAnnotation", "ParamKeyAnnotation", "value", "self", "annotations", "UrlParser", "constructor", "_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 2020 DXOS.org\n//\n\nimport { AST, JSONSchema, Schema as S } from '@effect/schema';\nimport type * as Types from 'effect/Types';\n\n// TODO(dmaretskyi): Remove re-exports.\nexport { AST, JSONSchema, S, Types };\n\nexport * from './ast';\nexport * from './url';\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { AST, Schema as S } from '@effect/schema';\nimport { Option, pipe } from 'effect';\n\nimport { invariant } from '@dxos/invariant';\nimport { nonNullable } from '@dxos/util';\n\n//\n// Refs\n// https://effect.website/docs/schema/introduction\n// https://www.npmjs.com/package/@effect/schema\n// https://effect-ts.github.io/effect/schema/AST.ts.html\n//\n\nexport type SimpleType = 'object' | 'string' | 'number' | 'boolean' | 'enum' | 'literal';\n\n/**\n * Get the base type; e.g., traverse through refinements.\n */\nexport const getSimpleType = (node: AST.AST): SimpleType | undefined => {\n if (AST.isObjectKeyword(node) || AST.isTypeLiteral(node) || isDiscriminatedUnion(node) || AST.isDeclaration(node)) {\n return 'object';\n }\n\n if (AST.isStringKeyword(node)) {\n return 'string';\n }\n if (AST.isNumberKeyword(node)) {\n return 'number';\n }\n if (AST.isBooleanKeyword(node)) {\n return 'boolean';\n }\n\n if (AST.isEnums(node)) {\n return 'enum';\n }\n\n if (AST.isLiteral(node)) {\n return 'literal';\n }\n};\n\nexport const isSimpleType = (node: AST.AST): boolean => !!getSimpleType(node);\n\nexport namespace SimpleType {\n /**\n * Returns the default empty value for a given SimpleType.\n * Used for initializing new array values etc.\n */\n export const getDefaultValue = (type: SimpleType): any => {\n switch (type) {\n case 'string': {\n return '';\n }\n case 'number': {\n return 0;\n }\n case 'boolean': {\n return false;\n }\n case 'object': {\n return {};\n }\n default: {\n throw new Error(`Unsupported type for default value: ${type}`);\n }\n }\n };\n}\n\n//\n// Branded types\n//\n\nexport type JsonProp = string & { __JsonPath: true; __JsonProp: true };\nexport type JsonPath = string & { __JsonPath: true };\n\nconst PATH_REGEX = /^[a-zA-Z_$][\\w$]*(?:\\.[a-zA-Z_$][\\w$]*|\\[\\d+\\])*$/;\nconst PROP_REGEX = /\\w+/;\n\n/**\n * https://www.ietf.org/archive/id/draft-goessner-dispatch-jsonpath-00.html\n */\nexport const JsonPath = S.NonEmptyString.pipe(S.pattern(PATH_REGEX)) as any as S.Schema<JsonPath>;\nexport const JsonProp = S.NonEmptyString.pipe(S.pattern(PROP_REGEX)) as any as S.Schema<JsonProp>;\n\nexport enum VisitResult {\n CONTINUE = 0,\n /**\n * Skip visiting children.\n */\n SKIP = 1,\n /**\n * Stop traversing immediately.\n */\n EXIT = 2,\n}\n\nexport type Path = (string | number)[];\n\nexport type TestFn = (node: AST.AST, path: Path, depth: number) => VisitResult | boolean | undefined;\n\nexport type VisitorFn = (node: AST.AST, path: Path, depth: number) => void;\n\nconst defaultTest: TestFn = isSimpleType;\n\n/**\n * Visit leaf nodes.\n * Refs:\n * - https://github.com/syntax-tree/unist-util-visit?tab=readme-ov-file#visitor\n * - https://github.com/syntax-tree/unist-util-is?tab=readme-ov-file#test\n */\nexport const visit: {\n (node: AST.AST, visitor: VisitorFn): void;\n (node: AST.AST, test: TestFn, visitor: VisitorFn): void;\n} = (node: AST.AST, testOrVisitor: TestFn | VisitorFn, visitor?: VisitorFn): void => {\n if (!visitor) {\n visitNode(node, defaultTest, testOrVisitor);\n } else {\n visitNode(node, testOrVisitor as TestFn, visitor);\n }\n};\n\nconst visitNode = (\n node: AST.AST,\n test: TestFn | undefined,\n visitor: VisitorFn,\n path: Path = [],\n depth = 0,\n): VisitResult | undefined => {\n const _result = test?.(node, path, depth);\n const result: VisitResult =\n _result === undefined\n ? VisitResult.CONTINUE\n : typeof _result === 'boolean'\n ? _result\n ? VisitResult.CONTINUE\n : VisitResult.SKIP\n : _result;\n\n if (result === VisitResult.EXIT) {\n return result;\n }\n if (result !== VisitResult.SKIP) {\n visitor(node, path, depth);\n }\n\n // Object.\n if (AST.isTypeLiteral(node)) {\n for (const prop of AST.getPropertySignatures(node)) {\n const currentPath = [...path, prop.name.toString()];\n const result = visitNode(prop.type, test, visitor, currentPath, depth + 1);\n if (result === VisitResult.EXIT) {\n return result;\n }\n }\n }\n\n // Array.\n else if (AST.isTupleType(node)) {\n for (const [i, element] of node.elements.entries()) {\n const currentPath = [...path, i];\n const result = visitNode(element.type, test, visitor, currentPath, depth);\n if (result === VisitResult.EXIT) {\n return result;\n }\n }\n }\n\n // Branching union (e.g., optional, discriminated unions).\n else if (AST.isUnion(node)) {\n for (const type of node.types) {\n const result = visitNode(type, test, visitor, path, depth);\n if (result === VisitResult.EXIT) {\n return result;\n }\n }\n }\n\n // Refinement.\n else if (AST.isRefinement(node)) {\n const result = visitNode(node.from, test, visitor, path, depth);\n if (result === VisitResult.EXIT) {\n return result;\n }\n }\n\n // TODO(burdon): Transforms?\n};\n\n/**\n * Recursively descend into AST to find first node that passes the test.\n */\n// TODO(burdon): Rewrite using visitNode?\nexport const findNode = (node: AST.AST, test: (node: AST.AST) => boolean): AST.AST | undefined => {\n if (test(node)) {\n return node;\n }\n\n // Object.\n else if (AST.isTypeLiteral(node)) {\n for (const prop of AST.getPropertySignatures(node)) {\n const child = findNode(prop.type, test);\n if (child) {\n return child;\n }\n }\n }\n\n // Tuple.\n else if (AST.isTupleType(node)) {\n for (const [_, element] of node.elements.entries()) {\n const child = findNode(element.type, test);\n if (child) {\n return child;\n }\n }\n }\n\n // Branching union (e.g., optional, discriminated unions).\n else if (AST.isUnion(node)) {\n if (isOption(node)) {\n for (const type of node.types) {\n const child = findNode(type, test);\n if (child) {\n return child;\n }\n }\n }\n }\n\n // Refinement.\n else if (AST.isRefinement(node)) {\n return findNode(node.from, test);\n }\n};\n\n/**\n * Get the AST node for the given property (dot-path).\n */\nexport const findProperty = (schema: S.Schema<any>, path: JsonPath | JsonProp): AST.AST | undefined => {\n const getProp = (node: AST.AST, path: JsonProp[]): AST.AST | undefined => {\n const [name, ...rest] = path;\n const typeNode = findNode(node, AST.isTypeLiteral);\n invariant(typeNode);\n for (const prop of AST.getPropertySignatures(typeNode)) {\n if (prop.name === name) {\n if (rest.length) {\n return getProp(prop.type, rest);\n } else {\n return prop.type;\n }\n }\n }\n };\n\n return getProp(schema.ast, path.split('.') as JsonProp[]);\n};\n\n//\n// Annotations\n//\n\nconst defaultAnnotations: Record<string, AST.Annotated> = {\n ['ObjectKeyword' as const]: AST.objectKeyword,\n ['StringKeyword' as const]: AST.stringKeyword,\n ['NumberKeyword' as const]: AST.numberKeyword,\n ['BooleanKeyword' as const]: AST.booleanKeyword,\n};\n\n/**\n * Get annotation or return undefined.\n * @param annotationId\n * @param noDefault If true, then return undefined for effect library defined values.\n */\nexport const getAnnotation =\n <T>(annotationId: symbol, noDefault = true) =>\n (node: AST.AST): T | undefined => {\n // Title fallback seems to be the identifier.\n const id = pipe(AST.getIdentifierAnnotation(node), Option.getOrUndefined);\n const value = pipe(AST.getAnnotation<T>(annotationId)(node), Option.getOrUndefined);\n if (noDefault && (value === defaultAnnotations[node._tag]?.annotations[annotationId] || value === id)) {\n return undefined;\n }\n\n return value;\n };\n\n/**\n * Recursively descend into AST to find first matching annotations.\n * Optionally skips default annotations for basic types (e.g., 'a string').\n */\n// TODO(burdon): Convert to effect pattern (i.e., return operator like getAnnotation).\nexport const findAnnotation = <T>(node: AST.AST, annotationId: symbol, noDefault = true): T | undefined => {\n const getAnnotationById = getAnnotation(annotationId, noDefault);\n\n const getBaseAnnotation = (node: AST.AST): T | undefined => {\n const value = getAnnotationById(node);\n if (value !== undefined) {\n return value as T;\n }\n\n if (AST.isUnion(node)) {\n if (isOption(node)) {\n return getAnnotationById(node.types[0]) as T;\n }\n }\n };\n\n return getBaseAnnotation(node);\n};\n\n//\n// Unions\n//\n\n/**\n * Effect S.optional creates a union type with undefined as the second type.\n */\nexport const isOption = (node: AST.AST): boolean => {\n return AST.isUnion(node) && node.types.length === 2 && AST.isUndefinedKeyword(node.types[1]);\n};\n\n/**\n * Determines if the node is a union of literal types.\n */\nexport const isLiteralUnion = (node: AST.AST): boolean => {\n return AST.isUnion(node) && node.types.every(AST.isLiteral);\n};\n\n/**\n * Determines if the node is a discriminated union.\n */\nexport const isDiscriminatedUnion = (node: AST.AST): boolean => {\n return AST.isUnion(node) && !!getDiscriminatingProps(node)?.length;\n};\n\n/**\n * Get the discriminating properties for the given union type.\n */\nexport const getDiscriminatingProps = (node: AST.AST): string[] | undefined => {\n invariant(AST.isUnion(node));\n if (isOption(node)) {\n return;\n }\n\n // Get common literals across all types.\n return node.types.reduce<string[]>((shared, type) => {\n const props = AST.getPropertySignatures(type)\n // TODO(burdon): Should check each literal is unique.\n .filter((p) => AST.isLiteral(p.type))\n .map((p) => p.name.toString());\n\n // Return common literals.\n return shared.length === 0 ? props : shared.filter((prop) => props.includes(prop));\n }, []);\n};\n\n/**\n * Get the discriminated type for the given value.\n */\nexport const getDiscriminatedType = (node: AST.AST, value: Record<string, any> = {}): AST.AST | undefined => {\n invariant(AST.isUnion(node));\n invariant(value);\n const props = getDiscriminatingProps(node);\n if (!props?.length) {\n return;\n }\n\n // Match provided values.\n for (const type of node.types) {\n const match = AST.getPropertySignatures(type)\n .filter((prop) => props?.includes(prop.name.toString()))\n .every((prop) => {\n invariant(AST.isLiteral(prop.type));\n return prop.type.literal === value[prop.name.toString()];\n });\n\n if (match) {\n return type;\n }\n }\n\n // Create union of discriminating properties.\n // NOTE: This may not work with non-overlapping variants.\n // TODO(burdon): Iterate through props and knock-out variants that don't match.\n const fields = Object.fromEntries(\n props\n .map((prop) => {\n const literals = node.types\n .map((type) => {\n const literal = AST.getPropertySignatures(type).find((p) => p.name.toString() === prop)!;\n invariant(AST.isLiteral(literal.type));\n return literal.type.literal;\n })\n .filter(nonNullable);\n\n return literals.length ? [prop, S.Literal(...literals)] : undefined;\n })\n .filter(nonNullable),\n );\n\n const schema = S.Struct(fields);\n return schema.ast;\n};\n\n/**\n * Maps AST nodes.\n * The user is responsible for recursively calling {@link mapAst} on the AST.\n * NOTE: Will evaluate suspended ASTs.\n */\nexport const mapAst = (ast: AST.AST, f: (ast: AST.AST, key: keyof any | undefined) => AST.AST): AST.AST => {\n switch (ast._tag) {\n case 'TypeLiteral':\n return new AST.TypeLiteral(\n ast.propertySignatures.map(\n (prop) =>\n new AST.PropertySignature(\n prop.name,\n f(prop.type, prop.name),\n prop.isOptional,\n prop.isReadonly,\n prop.annotations,\n ),\n ),\n ast.indexSignatures,\n );\n case 'Union':\n return AST.Union.make(ast.types.map(f), ast.annotations);\n case 'TupleType':\n return new AST.TupleType(\n ast.elements.map((t, index) => new AST.OptionalType(f(t.type, index), t.isOptional, t.annotations)),\n ast.rest.map((t) => new AST.Type(f(t.type, undefined), t.annotations)),\n ast.isReadonly,\n ast.annotations,\n );\n case 'Suspend': {\n const newAst = f(ast.f(), undefined);\n return new AST.Suspend(() => newAst, ast.annotations);\n }\n default:\n // TODO(dmaretskyi): Support more nodes.\n return ast;\n }\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { AST, type Schema as S } from '@effect/schema';\nimport { Option, pipe } from 'effect';\n\nimport { decamelize } from '@dxos/util';\n\nconst ParamKeyAnnotationId = Symbol.for('@dxos/schema/annotation/ParamKey');\n\ntype ParamKeyAnnotationValue = { key: string };\n\nexport const getParamKeyAnnotation: (annotated: AST.Annotated) => Option.Option<ParamKeyAnnotationValue> =\n AST.getAnnotation<ParamKeyAnnotationValue>(ParamKeyAnnotationId);\n\nexport const ParamKeyAnnotation =\n (value: ParamKeyAnnotationValue) =>\n <S extends S.Annotable.All>(self: S): S.Annotable.Self<S> =>\n self.annotations({ [ParamKeyAnnotationId]: value });\n\n/**\n * HTTP params parser.\n * Supports custom key serialization.\n */\nexport class UrlParser<T extends Record<string, any>> {\n constructor(private readonly _schema: S.Struct<T>) {}\n\n /**\n * Parse URL params.\n */\n parse(_url: string): T {\n const url = new URL(_url);\n return Object.entries(this._schema.fields).reduce<Record<string, any>>((params, [key, type]) => {\n let value = url.searchParams.get(decamelize(key));\n if (value == null) {\n value = url.searchParams.get(key);\n }\n\n if (value != null) {\n if (AST.isNumberKeyword(type.ast)) {\n params[key] = parseInt(value);\n } else if (AST.isBooleanKeyword(type.ast)) {\n params[key] = value === 'true' || value === '1';\n } else {\n params[key] = value;\n }\n }\n\n return params;\n }, {}) as T;\n }\n\n /**\n * Return URL with encoded params.\n */\n create(_url: string, params: T): URL {\n const url = new URL(_url);\n Object.entries(params).forEach(([key, value]) => {\n if (value !== undefined) {\n const field = this._schema.fields[key];\n if (field) {\n const { key: serializedKey } = pipe(\n getParamKeyAnnotation(field.ast),\n Option.getOrElse(() => ({\n key: decamelize(key),\n })),\n );\n\n url.searchParams.set(serializedKey, String(value));\n }\n }\n });\n\n return url;\n }\n}\n"],
5
+ "mappings": ";;;AAIA,SAASA,OAAAA,MAAKC,YAAYC,UAAUC,UAAS;;;ACA7C,SAASC,KAAKC,UAAUC,SAAS;AACjC,SAASC,QAAQC,YAAY;AAE7B,SAASC,iBAAiB;AAC1B,SAASC,mBAAmB;;AAcrB,IAAMC,gBAAgB,CAACC,SAAAA;AAC5B,MAAIR,IAAIS,gBAAgBD,IAAAA,KAASR,IAAIU,cAAcF,IAAAA,KAASG,qBAAqBH,IAAAA,KAASR,IAAIY,cAAcJ,IAAAA,GAAO;AACjH,WAAO;EACT;AAEA,MAAIR,IAAIa,gBAAgBL,IAAAA,GAAO;AAC7B,WAAO;EACT;AACA,MAAIR,IAA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C,GAAAA,IAAOf,UAAU,UAAUA,UAAU;QAC9C,OAAO;AACLc,iBAAOC,GAAAA,IAAOf;QAChB;MACF;AAEA,aAAOc;IACT,GAAG,CAAC,CAAA;EACN;;;;EAKAU,OAAOjB,MAAcO,QAAgB;AACnC,UAAMN,MAAM,IAAIC,IAAIF,IAAAA;AACpBG,WAAOC,QAAQG,MAAAA,EAAQW,QAAQ,CAAC,CAACV,KAAKf,KAAAA,MAAM;AAC1C,UAAIA,UAAU0B,QAAW;AACvB,cAAMC,QAAQ,KAAKtB,QAAQO,OAAOG,GAAAA;AAClC,YAAIY,OAAO;AACT,gBAAM,EAAEZ,KAAKa,cAAa,IAAKC,MAC7BjC,sBAAsB+B,MAAMN,GAAG,GAC/BS,QAAOC,UAAU,OAAO;YACtBhB,KAAKI,WAAWJ,GAAAA;UAClB,EAAA,CAAA;AAGFP,cAAIS,aAAae,IAAIJ,eAAeK,OAAOjC,KAAAA,CAAAA;QAC7C;MACF;IACF,CAAA;AAEA,WAAOQ;EACT;AACF;",
6
+ "names": ["AST", "JSONSchema", "Schema", "S", "AST", "Schema", "S", "Option", "pipe", "invariant", "nonNullable", "getSimpleType", "node", "isObjectKeyword", "isTypeLiteral", "isDiscriminatedUnion", "isDeclaration", "isStringKeyword", "isNumberKeyword", "isBooleanKeyword", "isEnums", "isLiteral", "isSimpleType", "SimpleType", "getDefaultValue", "type", "Error", "PATH_REGEX", "PROP_REGEX", "JsonPath", "NonEmptyString", "pattern", "JsonProp", "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", "AST", "Option", "pipe", "decamelize", "ParamKeyAnnotationId", "Symbol", "for", "getParamKeyAnnotation", "AST", "getAnnotation", "ParamKeyAnnotation", "value", "self", "annotations", "UrlParser", "constructor", "_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":41444,"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/effect/src/url.ts":{"bytes":7711,"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/effect/src/index.ts":{"bytes":1150,"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"packages/common/effect/src/ast.ts","kind":"import-statement","original":"./ast"},{"path":"packages/common/effect/src/url.ts","kind":"import-statement","original":"./url"}],"format":"esm"}},"outputs":{"packages/common/effect/dist/lib/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":25493},"packages/common/effect/dist/lib/node-esm/index.mjs":{"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["AST","JSONSchema","JsonPath","JsonProp","ParamKeyAnnotation","S","SimpleType","UrlParser","VisitResult","findAnnotation","findNode","findProperty","getAnnotation","getDiscriminatedType","getDiscriminatingProps","getParamKeyAnnotation","getSimpleType","isDiscriminatedUnion","isLiteralUnion","isOption","isSimpleType","mapAst","visit"],"entryPoint":"packages/common/effect/src/index.ts","inputs":{"packages/common/effect/src/index.ts":{"bytesInOutput":72},"packages/common/effect/src/ast.ts":{"bytesInOutput":8647},"packages/common/effect/src/url.ts":{"bytesInOutput":1624}},"bytes":10969}}}
1
+ {"inputs":{"packages/common/effect/src/ast.ts":{"bytes":41924,"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/effect/src/url.ts":{"bytes":7711,"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/effect/src/index.ts":{"bytes":1150,"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"packages/common/effect/src/ast.ts","kind":"import-statement","original":"./ast"},{"path":"packages/common/effect/src/url.ts","kind":"import-statement","original":"./url"}],"format":"esm"}},"outputs":{"packages/common/effect/dist/lib/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":25791},"packages/common/effect/dist/lib/node-esm/index.mjs":{"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["AST","JSONSchema","JsonPath","JsonProp","ParamKeyAnnotation","S","SimpleType","UrlParser","VisitResult","findAnnotation","findNode","findProperty","getAnnotation","getDiscriminatedType","getDiscriminatingProps","getParamKeyAnnotation","getSimpleType","isDiscriminatedUnion","isLiteralUnion","isOption","isSimpleType","mapAst","visit"],"entryPoint":"packages/common/effect/src/index.ts","inputs":{"packages/common/effect/src/index.ts":{"bytesInOutput":72},"packages/common/effect/src/ast.ts":{"bytesInOutput":8725},"packages/common/effect/src/url.ts":{"bytesInOutput":1624}},"bytes":11047}}}
@@ -92,5 +92,5 @@ export declare const getDiscriminatedType: (node: AST.AST, value?: Record<string
92
92
  * The user is responsible for recursively calling {@link mapAst} on the AST.
93
93
  * NOTE: Will evaluate suspended ASTs.
94
94
  */
95
- export declare const mapAst: (ast: AST.AST, f: (ast: AST.AST) => AST.AST) => AST.AST;
95
+ export declare const mapAst: (ast: AST.AST, f: (ast: AST.AST, key: keyof any | undefined) => AST.AST) => AST.AST;
96
96
  //# sourceMappingURL=ast.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../../../src/ast.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,GAAG,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,gBAAgB,CAAC;AAalD,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAAC;AAEzF;;GAEG;AACH,eAAO,MAAM,aAAa,SAAU,GAAG,CAAC,GAAG,KAAG,UAAU,GAAG,SAsB1D,CAAC;AAEF,eAAO,MAAM,YAAY,SAAU,GAAG,CAAC,GAAG,KAAG,OAAgC,CAAC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B,SAAU,GAAG,CAAC,GAAG,UAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAQ,GAAG,CAAC,GAAG,GAAG,SA2C/F,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,MAAM,QAAS,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,GAAG,GAAG,SAAS,KAAK,GAAG,CAAC,GAAG,KAAG,GAAG,CAAC,GAiCnG,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":"5.7.2"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/effect",
3
- "version": "0.7.4",
3
+ "version": "0.7.5-feature-compute.4d9d99a",
4
4
  "description": "Effect utils.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -22,18 +22,18 @@
22
22
  "src"
23
23
  ],
24
24
  "dependencies": {
25
- "@dxos/invariant": "0.7.4",
26
- "@dxos/node-std": "0.7.4",
27
- "@dxos/util": "0.7.4"
25
+ "@dxos/util": "0.7.5-feature-compute.4d9d99a",
26
+ "@dxos/invariant": "0.7.5-feature-compute.4d9d99a",
27
+ "@dxos/node-std": "0.7.5-feature-compute.4d9d99a"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@effect/schema": "^0.75.5",
31
- "effect": "^3.9.2",
32
- "@dxos/log": "0.7.4"
31
+ "effect": "^3.12.3",
32
+ "@dxos/log": "0.7.5-feature-compute.4d9d99a"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "@effect/schema": "^0.75.5",
36
- "effect": "^3.9.2"
36
+ "effect": "^3.12.3"
37
37
  },
38
38
  "publishConfig": {
39
39
  "access": "public"
package/src/ast.test.ts CHANGED
@@ -3,6 +3,7 @@
3
3
  //
4
4
 
5
5
  import { AST, Schema as S } from '@effect/schema';
6
+ import { isNone, isSome } from 'effect/Option';
6
7
  import { describe, test } from 'vitest';
7
8
 
8
9
  import { invariant } from '@dxos/invariant';
@@ -18,7 +19,7 @@ import {
18
19
  isOption,
19
20
  isSimpleType,
20
21
  visit,
21
- type JsonPath,
22
+ JsonPath,
22
23
  type JsonProp,
23
24
  } from './ast';
24
25
 
@@ -182,4 +183,25 @@ describe('AST', () => {
182
183
  );
183
184
  }
184
185
  });
186
+
187
+ // TODO(ZaymonFC): Update this when we settle on the right indexing syntax for arrays.
188
+ test('json path validation', ({ expect }) => {
189
+ const validatePath = S.validateOption(JsonPath);
190
+
191
+ // Valid paths.
192
+ expect(isSome(validatePath('foo'))).toBe(true);
193
+ expect(isSome(validatePath('foo.bar'))).toBe(true);
194
+ expect(isSome(validatePath('foo.bar.baz'))).toBe(true);
195
+ expect(isSome(validatePath('foo[1].bar'))).toBe(true);
196
+ expect(isSome(validatePath('_foo.$bar'))).toBe(true);
197
+
198
+ // Invalid paths.
199
+ expect(isNone(validatePath(''))).toBe(true);
200
+ expect(isNone(validatePath('.'))).toBe(true);
201
+ expect(isNone(validatePath('foo.'))).toBe(true);
202
+ expect(isNone(validatePath('foo..bar'))).toBe(true);
203
+ expect(isNone(validatePath('foo.#bar'))).toBe(true);
204
+ expect(isNone(validatePath('[1].bar'))).toBe(true);
205
+ expect(isNone(validatePath('test.[1].bar[1]'))).toBe(true);
206
+ });
185
207
  });
package/src/ast.ts CHANGED
@@ -21,7 +21,7 @@ export type SimpleType = 'object' | 'string' | 'number' | 'boolean' | 'enum' | '
21
21
  * Get the base type; e.g., traverse through refinements.
22
22
  */
23
23
  export const getSimpleType = (node: AST.AST): SimpleType | undefined => {
24
- if (AST.isObjectKeyword(node) || AST.isTypeLiteral(node) || isDiscriminatedUnion(node)) {
24
+ if (AST.isObjectKeyword(node) || AST.isTypeLiteral(node) || isDiscriminatedUnion(node) || AST.isDeclaration(node)) {
25
25
  return 'object';
26
26
  }
27
27
 
@@ -79,7 +79,7 @@ export namespace SimpleType {
79
79
  export type JsonProp = string & { __JsonPath: true; __JsonProp: true };
80
80
  export type JsonPath = string & { __JsonPath: true };
81
81
 
82
- const PATH_REGEX = /[a-zA-Z_$][\w$]*(?:\.[a-zA-Z_$][\w$]*)*/;
82
+ const PATH_REGEX = /^[a-zA-Z_$][\w$]*(?:\.[a-zA-Z_$][\w$]*|\[\d+\])*$/;
83
83
  const PROP_REGEX = /\w+/;
84
84
 
85
85
  /**
@@ -413,13 +413,19 @@ export const getDiscriminatedType = (node: AST.AST, value: Record<string, any> =
413
413
  * The user is responsible for recursively calling {@link mapAst} on the AST.
414
414
  * NOTE: Will evaluate suspended ASTs.
415
415
  */
416
- export const mapAst = (ast: AST.AST, f: (ast: AST.AST) => AST.AST): AST.AST => {
416
+ export const mapAst = (ast: AST.AST, f: (ast: AST.AST, key: keyof any | undefined) => AST.AST): AST.AST => {
417
417
  switch (ast._tag) {
418
418
  case 'TypeLiteral':
419
419
  return new AST.TypeLiteral(
420
420
  ast.propertySignatures.map(
421
421
  (prop) =>
422
- new AST.PropertySignature(prop.name, f(prop.type), prop.isOptional, prop.isReadonly, prop.annotations),
422
+ new AST.PropertySignature(
423
+ prop.name,
424
+ f(prop.type, prop.name),
425
+ prop.isOptional,
426
+ prop.isReadonly,
427
+ prop.annotations,
428
+ ),
423
429
  ),
424
430
  ast.indexSignatures,
425
431
  );
@@ -427,13 +433,13 @@ export const mapAst = (ast: AST.AST, f: (ast: AST.AST) => AST.AST): AST.AST => {
427
433
  return AST.Union.make(ast.types.map(f), ast.annotations);
428
434
  case 'TupleType':
429
435
  return new AST.TupleType(
430
- ast.elements.map((t) => new AST.OptionalType(f(t.type), t.isOptional, t.annotations)),
431
- ast.rest.map((t) => new AST.Type(f(t.type), t.annotations)),
436
+ ast.elements.map((t, index) => new AST.OptionalType(f(t.type, index), t.isOptional, t.annotations)),
437
+ ast.rest.map((t) => new AST.Type(f(t.type, undefined), t.annotations)),
432
438
  ast.isReadonly,
433
439
  ast.annotations,
434
440
  );
435
441
  case 'Suspend': {
436
- const newAst = f(ast.f());
442
+ const newAst = f(ast.f(), undefined);
437
443
  return new AST.Suspend(() => newAst, ast.annotations);
438
444
  }
439
445
  default: