@dxos/effect 0.8.0 → 0.8.1-main.ae460ac
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.
- package/dist/lib/browser/index.mjs +9 -17
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +56 -65
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +9 -17
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/ast.d.ts +1 -1
- package/dist/types/src/ast.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +0 -3
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/jsonPath.d.ts +1 -1
- package/dist/types/src/jsonPath.d.ts.map +1 -1
- package/dist/types/src/url.d.ts +1 -2
- package/dist/types/src/url.d.ts.map +1 -1
- package/package.json +5 -7
- package/src/ast.test.ts +1 -1
- package/src/ast.ts +1 -2
- package/src/index.ts +0 -6
- package/src/jsonPath.ts +1 -1
- package/src/url.test.ts +1 -1
- package/src/url.ts +1 -2
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import "@dxos/node-std/globals";
|
|
2
2
|
|
|
3
|
-
// packages/common/effect/src/index.ts
|
|
4
|
-
import { AST as AST3, JSONSchema, Schema as S3 } from "@effect/schema";
|
|
5
|
-
|
|
6
3
|
// packages/common/effect/src/ast.ts
|
|
7
|
-
import { AST, Schema as S } from "
|
|
8
|
-
import { Option, pipe } from "effect";
|
|
4
|
+
import { Option, pipe, SchemaAST as AST, Schema as S } from "effect";
|
|
9
5
|
import { invariant } from "@dxos/invariant";
|
|
10
6
|
import { isNonNullable } from "@dxos/util";
|
|
11
7
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/common/effect/src/ast.ts";
|
|
@@ -147,7 +143,7 @@ var findProperty = (schema, path) => {
|
|
|
147
143
|
const typeNode = findNode(node, AST.isTypeLiteral);
|
|
148
144
|
invariant(typeNode, void 0, {
|
|
149
145
|
F: __dxlog_file,
|
|
150
|
-
L:
|
|
146
|
+
L: 238,
|
|
151
147
|
S: void 0,
|
|
152
148
|
A: [
|
|
153
149
|
"typeNode",
|
|
@@ -207,7 +203,7 @@ var isDiscriminatedUnion = (node) => {
|
|
|
207
203
|
var getDiscriminatingProps = (node) => {
|
|
208
204
|
invariant(AST.isUnion(node), void 0, {
|
|
209
205
|
F: __dxlog_file,
|
|
210
|
-
L:
|
|
206
|
+
L: 335,
|
|
211
207
|
S: void 0,
|
|
212
208
|
A: [
|
|
213
209
|
"AST.isUnion(node)",
|
|
@@ -225,7 +221,7 @@ var getDiscriminatingProps = (node) => {
|
|
|
225
221
|
var getDiscriminatedType = (node, value = {}) => {
|
|
226
222
|
invariant(AST.isUnion(node), void 0, {
|
|
227
223
|
F: __dxlog_file,
|
|
228
|
-
L:
|
|
224
|
+
L: 356,
|
|
229
225
|
S: void 0,
|
|
230
226
|
A: [
|
|
231
227
|
"AST.isUnion(node)",
|
|
@@ -234,7 +230,7 @@ var getDiscriminatedType = (node, value = {}) => {
|
|
|
234
230
|
});
|
|
235
231
|
invariant(value, void 0, {
|
|
236
232
|
F: __dxlog_file,
|
|
237
|
-
L:
|
|
233
|
+
L: 357,
|
|
238
234
|
S: void 0,
|
|
239
235
|
A: [
|
|
240
236
|
"value",
|
|
@@ -249,7 +245,7 @@ var getDiscriminatedType = (node, value = {}) => {
|
|
|
249
245
|
const match = AST.getPropertySignatures(type).filter((prop) => props?.includes(prop.name.toString())).every((prop) => {
|
|
250
246
|
invariant(AST.isLiteral(prop.type), void 0, {
|
|
251
247
|
F: __dxlog_file,
|
|
252
|
-
L:
|
|
248
|
+
L: 368,
|
|
253
249
|
S: void 0,
|
|
254
250
|
A: [
|
|
255
251
|
"AST.isLiteral(prop.type)",
|
|
@@ -267,7 +263,7 @@ var getDiscriminatedType = (node, value = {}) => {
|
|
|
267
263
|
const literal = AST.getPropertySignatures(type).find((p) => p.name.toString() === prop);
|
|
268
264
|
invariant(AST.isLiteral(literal.type), void 0, {
|
|
269
265
|
F: __dxlog_file,
|
|
270
|
-
L:
|
|
266
|
+
L: 386,
|
|
271
267
|
S: void 0,
|
|
272
268
|
A: [
|
|
273
269
|
"AST.isLiteral(literal.type)",
|
|
@@ -302,7 +298,7 @@ var mapAst = (ast, f) => {
|
|
|
302
298
|
};
|
|
303
299
|
|
|
304
300
|
// packages/common/effect/src/jsonPath.ts
|
|
305
|
-
import { Schema as S2 } from "
|
|
301
|
+
import { Schema as S2 } from "effect";
|
|
306
302
|
import { isSome } from "effect/Option";
|
|
307
303
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
308
304
|
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/common/effect/src/jsonPath.ts";
|
|
@@ -353,8 +349,7 @@ var splitJsonPath = (path) => {
|
|
|
353
349
|
};
|
|
354
350
|
|
|
355
351
|
// packages/common/effect/src/url.ts
|
|
356
|
-
import {
|
|
357
|
-
import { Option as Option2, pipe as pipe2 } from "effect";
|
|
352
|
+
import { SchemaAST as AST2, Option as Option2, pipe as pipe2 } from "effect";
|
|
358
353
|
import { decamelize } from "@dxos/util";
|
|
359
354
|
var ParamKeyAnnotationId = Symbol.for("@dxos/schema/annotation/ParamKey");
|
|
360
355
|
var getParamKeyAnnotation = AST2.getAnnotation(ParamKeyAnnotationId);
|
|
@@ -407,12 +402,9 @@ var UrlParser = class {
|
|
|
407
402
|
}
|
|
408
403
|
};
|
|
409
404
|
export {
|
|
410
|
-
AST3 as AST,
|
|
411
|
-
JSONSchema,
|
|
412
405
|
JsonPath,
|
|
413
406
|
JsonProp,
|
|
414
407
|
ParamKeyAnnotation,
|
|
415
|
-
S3 as S,
|
|
416
408
|
SimpleType,
|
|
417
409
|
UrlParser,
|
|
418
410
|
VisitResult,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2020 DXOS.org\n//\n\nimport { AST, JSONSchema, Schema as S } from '@effect/schema';\nimport type * as Types from 'effect/Types';\n\n// TODO(dmaretskyi): Remove re-exports.\nexport { AST, JSONSchema, S, Types };\n\nexport * from './ast';\nexport * from './jsonPath';\nexport * from './url';\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { AST, Schema as S } from '@effect/schema';\nimport { Option, pipe } from 'effect';\n\nimport { invariant } from '@dxos/invariant';\nimport { isNonNullable } from '@dxos/util';\n\nimport { type JsonPath, type JsonProp } from './jsonPath';\n\n//\n// Refs\n// https://effect.website/docs/schema/introduction\n// https://www.npmjs.com/package/@effect/schema\n// https://effect-ts.github.io/effect/schema/AST.ts.html\n//\n\nexport type SimpleType = 'object' | 'string' | 'number' | 'boolean' | 'enum' | 'literal';\n\n/**\n * Get the base type; e.g., traverse through refinements.\n */\nexport const getSimpleType = (node: AST.AST): SimpleType | undefined => {\n if (AST.isObjectKeyword(node) || AST.isTypeLiteral(node) || isDiscriminatedUnion(node) || AST.isDeclaration(node)) {\n return 'object';\n }\n\n if (AST.isStringKeyword(node)) {\n return 'string';\n }\n if (AST.isNumberKeyword(node)) {\n return 'number';\n }\n if (AST.isBooleanKeyword(node)) {\n return 'boolean';\n }\n\n if (AST.isEnums(node)) {\n return 'enum';\n }\n\n if (AST.isLiteral(node)) {\n return 'literal';\n }\n};\n\nexport const isSimpleType = (node: AST.AST): boolean => !!getSimpleType(node);\n\nexport namespace SimpleType {\n /**\n * Returns the default empty value for a given SimpleType.\n * Used for initializing new array values etc.\n */\n export const getDefaultValue = (type: SimpleType): any => {\n switch (type) {\n case 'string': {\n return '';\n }\n case 'number': {\n return 0;\n }\n case 'boolean': {\n return false;\n }\n case 'object': {\n return {};\n }\n default: {\n throw new Error(`Unsupported type for default value: ${type}`);\n }\n }\n };\n}\n\n//\n// Branded types\n//\n\nexport enum VisitResult {\n CONTINUE = 0,\n /**\n * Skip visiting children.\n */\n SKIP = 1,\n /**\n * Stop traversing immediately.\n */\n EXIT = 2,\n}\n\nexport type Path = (string | number)[];\n\nexport type TestFn = (node: AST.AST, path: Path, depth: number) => VisitResult | boolean | undefined;\n\nexport type VisitorFn = (node: AST.AST, path: Path, depth: number) => void;\n\nconst defaultTest: TestFn = isSimpleType;\n\n/**\n * Visit leaf nodes.\n * Refs:\n * - https://github.com/syntax-tree/unist-util-visit?tab=readme-ov-file#visitor\n * - https://github.com/syntax-tree/unist-util-is?tab=readme-ov-file#test\n */\nexport const visit: {\n (node: AST.AST, visitor: VisitorFn): void;\n (node: AST.AST, test: TestFn, visitor: VisitorFn): void;\n} = (node: AST.AST, testOrVisitor: TestFn | VisitorFn, visitor?: VisitorFn): void => {\n if (!visitor) {\n visitNode(node, defaultTest, testOrVisitor);\n } else {\n visitNode(node, testOrVisitor as TestFn, visitor);\n }\n};\n\nconst visitNode = (\n node: AST.AST,\n test: TestFn | undefined,\n visitor: VisitorFn,\n path: Path = [],\n depth = 0,\n): VisitResult | undefined => {\n const _result = test?.(node, path, depth);\n const result: VisitResult =\n _result === undefined\n ? VisitResult.CONTINUE\n : typeof _result === 'boolean'\n ? _result\n ? VisitResult.CONTINUE\n : VisitResult.SKIP\n : _result;\n\n if (result === VisitResult.EXIT) {\n return result;\n }\n if (result !== VisitResult.SKIP) {\n visitor(node, path, depth);\n }\n\n // Object.\n if (AST.isTypeLiteral(node)) {\n for (const prop of AST.getPropertySignatures(node)) {\n const currentPath = [...path, prop.name.toString()];\n const result = visitNode(prop.type, test, visitor, currentPath, depth + 1);\n if (result === VisitResult.EXIT) {\n return result;\n }\n }\n }\n\n // Array.\n else if (AST.isTupleType(node)) {\n for (const [i, element] of node.elements.entries()) {\n const currentPath = [...path, i];\n const result = visitNode(element.type, test, visitor, currentPath, depth);\n if (result === VisitResult.EXIT) {\n return result;\n }\n }\n }\n\n // Branching union (e.g., optional, discriminated unions).\n else if (AST.isUnion(node)) {\n for (const type of node.types) {\n const result = visitNode(type, test, visitor, path, depth);\n if (result === VisitResult.EXIT) {\n return result;\n }\n }\n }\n\n // Refinement.\n else if (AST.isRefinement(node)) {\n const result = visitNode(node.from, test, visitor, path, depth);\n if (result === VisitResult.EXIT) {\n return result;\n }\n }\n\n // TODO(burdon): Transforms?\n};\n\n/**\n * Recursively descend into AST to find first node that passes the test.\n */\n// TODO(burdon): Rewrite using visitNode?\nexport const findNode = (node: AST.AST, test: (node: AST.AST) => boolean): AST.AST | undefined => {\n if (test(node)) {\n return node;\n }\n\n // Object.\n else if (AST.isTypeLiteral(node)) {\n for (const prop of AST.getPropertySignatures(node)) {\n const child = findNode(prop.type, test);\n if (child) {\n return child;\n }\n }\n }\n\n // Tuple.\n else if (AST.isTupleType(node)) {\n for (const [_, element] of node.elements.entries()) {\n const child = findNode(element.type, test);\n if (child) {\n return child;\n }\n }\n }\n\n // Branching union (e.g., optional, discriminated unions).\n else if (AST.isUnion(node)) {\n if (isOption(node)) {\n for (const type of node.types) {\n const child = findNode(type, test);\n if (child) {\n return child;\n }\n }\n }\n }\n\n // Refinement.\n else if (AST.isRefinement(node)) {\n return findNode(node.from, test);\n }\n};\n\n/**\n * Get the AST node for the given property (dot-path).\n */\nexport const findProperty = (schema: S.Schema<any>, path: JsonPath | JsonProp): AST.AST | undefined => {\n const getProp = (node: AST.AST, path: JsonProp[]): AST.AST | undefined => {\n const [name, ...rest] = path;\n const typeNode = findNode(node, AST.isTypeLiteral);\n invariant(typeNode);\n for (const prop of AST.getPropertySignatures(typeNode)) {\n if (prop.name === name) {\n if (rest.length) {\n return getProp(prop.type, rest);\n } else {\n return prop.type;\n }\n }\n }\n };\n\n return getProp(schema.ast, path.split('.') as JsonProp[]);\n};\n\n//\n// Annotations\n//\n\nconst defaultAnnotations: Record<string, AST.Annotated> = {\n ['ObjectKeyword' as const]: AST.objectKeyword,\n ['StringKeyword' as const]: AST.stringKeyword,\n ['NumberKeyword' as const]: AST.numberKeyword,\n ['BooleanKeyword' as const]: AST.booleanKeyword,\n};\n\n/**\n * Get annotation or return undefined.\n * @param annotationId\n * @param noDefault If true, then return undefined for effect library defined values.\n */\nexport const getAnnotation =\n <T>(annotationId: symbol, noDefault = true) =>\n (node: AST.AST): T | undefined => {\n // Title fallback seems to be the identifier.\n const id = pipe(AST.getIdentifierAnnotation(node), Option.getOrUndefined);\n const value = pipe(AST.getAnnotation<T>(annotationId)(node), Option.getOrUndefined);\n if (noDefault && (value === defaultAnnotations[node._tag]?.annotations[annotationId] || value === id)) {\n return undefined;\n }\n\n return value;\n };\n\n/**\n * Recursively descend into AST to find first matching annotations.\n * Optionally skips default annotations for basic types (e.g., 'a string').\n */\n// TODO(burdon): Convert to effect pattern (i.e., return operator like getAnnotation).\nexport const findAnnotation = <T>(node: AST.AST, annotationId: symbol, noDefault = true): T | undefined => {\n const getAnnotationById = getAnnotation(annotationId, noDefault);\n\n const getBaseAnnotation = (node: AST.AST): T | undefined => {\n const value = getAnnotationById(node);\n if (value !== undefined) {\n return value as T;\n }\n\n if (AST.isUnion(node)) {\n if (isOption(node)) {\n return getAnnotationById(node.types[0]) as T;\n }\n }\n };\n\n return getBaseAnnotation(node);\n};\n\n//\n// Unions\n//\n\n/**\n * Effect S.optional creates a union type with undefined as the second type.\n */\nexport const isOption = (node: AST.AST): boolean => {\n return AST.isUnion(node) && node.types.length === 2 && AST.isUndefinedKeyword(node.types[1]);\n};\n\n/**\n * Determines if the node is a union of literal types.\n */\nexport const isLiteralUnion = (node: AST.AST): boolean => {\n return AST.isUnion(node) && node.types.every(AST.isLiteral);\n};\n\n/**\n * Determines if the node is a discriminated union.\n */\nexport const isDiscriminatedUnion = (node: AST.AST): boolean => {\n return AST.isUnion(node) && !!getDiscriminatingProps(node)?.length;\n};\n\n/**\n * Get the discriminating properties for the given union type.\n */\nexport const getDiscriminatingProps = (node: AST.AST): string[] | undefined => {\n invariant(AST.isUnion(node));\n if (isOption(node)) {\n return;\n }\n\n // Get common literals across all types.\n return node.types.reduce<string[]>((shared, type) => {\n const props = AST.getPropertySignatures(type)\n // TODO(burdon): Should check each literal is unique.\n .filter((p) => AST.isLiteral(p.type))\n .map((p) => p.name.toString());\n\n // Return common literals.\n return shared.length === 0 ? props : shared.filter((prop) => props.includes(prop));\n }, []);\n};\n\n/**\n * Get the discriminated type for the given value.\n */\nexport const getDiscriminatedType = (node: AST.AST, value: Record<string, any> = {}): AST.AST | undefined => {\n invariant(AST.isUnion(node));\n invariant(value);\n const props = getDiscriminatingProps(node);\n if (!props?.length) {\n return;\n }\n\n // Match provided values.\n for (const type of node.types) {\n const match = AST.getPropertySignatures(type)\n .filter((prop) => props?.includes(prop.name.toString()))\n .every((prop) => {\n invariant(AST.isLiteral(prop.type));\n return prop.type.literal === value[prop.name.toString()];\n });\n\n if (match) {\n return type;\n }\n }\n\n // Create union of discriminating properties.\n // NOTE: This may not work with non-overlapping variants.\n // TODO(burdon): Iterate through props and knock-out variants that don't match.\n const fields = Object.fromEntries(\n props\n .map((prop) => {\n const literals = node.types\n .map((type) => {\n const literal = AST.getPropertySignatures(type).find((p) => p.name.toString() === prop)!;\n invariant(AST.isLiteral(literal.type));\n return literal.type.literal;\n })\n .filter(isNonNullable);\n\n return literals.length ? [prop, S.Literal(...literals)] : undefined;\n })\n .filter(isNonNullable),\n );\n\n const schema = S.Struct(fields);\n return schema.ast;\n};\n\n/**\n * Maps AST nodes.\n * The user is responsible for recursively calling {@link mapAst} on the AST.\n * NOTE: Will evaluate suspended ASTs.\n */\nexport const mapAst = (ast: AST.AST, f: (ast: AST.AST, key: keyof any | undefined) => AST.AST): AST.AST => {\n switch (ast._tag) {\n case 'TypeLiteral':\n return new AST.TypeLiteral(\n ast.propertySignatures.map(\n (prop) =>\n new AST.PropertySignature(\n prop.name,\n f(prop.type, prop.name),\n prop.isOptional,\n prop.isReadonly,\n prop.annotations,\n ),\n ),\n ast.indexSignatures,\n );\n case 'Union':\n return AST.Union.make(ast.types.map(f), ast.annotations);\n case 'TupleType':\n return new AST.TupleType(\n ast.elements.map((t, index) => new AST.OptionalType(f(t.type, index), t.isOptional, t.annotations)),\n ast.rest.map((t) => new AST.Type(f(t.type, undefined), t.annotations)),\n ast.isReadonly,\n ast.annotations,\n );\n case 'Suspend': {\n const newAst = f(ast.f(), undefined);\n return new AST.Suspend(() => newAst, ast.annotations);\n }\n default:\n // TODO(dmaretskyi): Support more nodes.\n return ast;\n }\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Schema as S } from '@effect/schema';\nimport { isSome } from 'effect/Option';\n\nimport { invariant } from '@dxos/invariant';\n\nexport type JsonProp = string & { __JsonPath: true; __JsonProp: true };\nexport type JsonPath = string & { __JsonPath: true };\n\nconst PATH_REGEX = /^($|[a-zA-Z_$][\\w$]*(?:\\.[a-zA-Z_$][\\w$]*|\\[\\d+\\](?:\\.)?)*$)/;\nconst PROP_REGEX = /\\w+/;\n\n/**\n * https://www.ietf.org/archive/id/draft-goessner-dispatch-jsonpath-00.html\n */\nexport const JsonPath = S.String.pipe(S.pattern(PATH_REGEX)) as any as S.Schema<JsonPath>;\nexport const JsonProp = S.NonEmptyString.pipe(S.pattern(PROP_REGEX)) as any as S.Schema<JsonProp>;\n\nexport const isJsonPath = (value: unknown): value is JsonPath => {\n return isSome(S.validateOption(JsonPath)(value));\n};\n\n/**\n * Creates a JsonPath from an array of path segments.\n *\n * Currently supports:\n * - Simple property access (e.g., 'foo.bar')\n * - Array indexing with non-negative integers (e.g., 'foo[0]')\n * - Identifiers starting with letters, underscore, or $ (e.g., '$foo', '_bar')\n * - Dot notation for nested properties (e.g., 'foo.bar.baz')\n *\n * Does not support (yet?).\n * - Recursive descent (..)\n * - Wildcards (*)\n * - Array slicing\n * - Filters\n * - Negative indices\n *\n * @param path Array of string or number segments\n * @returns Valid JsonPath or undefined if invalid\n */\nexport const createJsonPath = (path: (string | number)[]): JsonPath => {\n const candidatePath = path\n .map((p, i) => {\n if (typeof p === 'number') {\n return `[${p}]`;\n } else {\n return i === 0 ? p : `.${p}`;\n }\n })\n .join('');\n\n invariant(isJsonPath(candidatePath), `Invalid JsonPath: ${candidatePath}`);\n return candidatePath;\n};\n\n/**\n * Converts Effect validation path format (e.g. \"addresses.[0].zip\")\n * to JsonPath format (e.g. \"addresses[0].zip\")\n */\nexport const fromEffectValidationPath = (effectPath: string): JsonPath => {\n // Handle array notation: convert \"prop.[0]\" to \"prop[0]\"\n const jsonPath = effectPath.replace(/\\.\\[(\\d+)\\]/g, '[$1]');\n invariant(isJsonPath(jsonPath), `Invalid JsonPath: ${jsonPath}`);\n return jsonPath;\n};\n\n/**\n * Splits a JsonPath into its constituent parts.\n * Handles property access and array indexing.\n */\nexport const splitJsonPath = (path: JsonPath): string[] => {\n if (!isJsonPath(path)) {\n return [];\n }\n\n return (\n path\n .match(/[a-zA-Z_$][\\w$]*|\\[\\d+\\]/g)\n ?.map((part) => (part.startsWith('[') ? part.replace(/[[\\]]/g, '') : part)) ?? []\n );\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { AST, type Schema as S } from '@effect/schema';\nimport { Option, pipe } from 'effect';\n\nimport { decamelize } from '@dxos/util';\n\nconst ParamKeyAnnotationId = Symbol.for('@dxos/schema/annotation/ParamKey');\n\ntype ParamKeyAnnotationValue = { key: string };\n\nexport const getParamKeyAnnotation: (annotated: AST.Annotated) => Option.Option<ParamKeyAnnotationValue> =\n AST.getAnnotation<ParamKeyAnnotationValue>(ParamKeyAnnotationId);\n\nexport const ParamKeyAnnotation =\n (value: ParamKeyAnnotationValue) =>\n <S extends S.Annotable.All>(self: S): S.Annotable.Self<S> =>\n self.annotations({ [ParamKeyAnnotationId]: value });\n\n/**\n * HTTP params parser.\n * Supports custom key serialization.\n */\nexport class UrlParser<T extends Record<string, any>> {\n constructor(private readonly _schema: S.Struct<T>) {}\n\n /**\n * Parse URL params.\n */\n parse(_url: string): T {\n const url = new URL(_url);\n return Object.entries(this._schema.fields).reduce<Record<string, any>>((params, [key, type]) => {\n let value = url.searchParams.get(decamelize(key));\n if (value == null) {\n value = url.searchParams.get(key);\n }\n\n if (value != null) {\n if (AST.isNumberKeyword(type.ast)) {\n params[key] = parseInt(value);\n } else if (AST.isBooleanKeyword(type.ast)) {\n params[key] = value === 'true' || value === '1';\n } else {\n params[key] = value;\n }\n }\n\n return params;\n }, {}) as T;\n }\n\n /**\n * Return URL with encoded params.\n */\n create(_url: string, params: T): URL {\n const url = new URL(_url);\n Object.entries(params).forEach(([key, value]) => {\n if (value !== undefined) {\n const field = this._schema.fields[key];\n if (field) {\n const { key: serializedKey } = pipe(\n getParamKeyAnnotation(field.ast),\n Option.getOrElse(() => ({\n key: decamelize(key),\n })),\n );\n\n url.searchParams.set(serializedKey, String(value));\n }\n }\n });\n\n return url;\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;AAIA,SAASA,
|
|
6
|
-
"names": ["
|
|
3
|
+
"sources": ["../../../src/ast.ts", "../../../src/jsonPath.ts", "../../../src/url.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { Option, pipe, SchemaAST as AST, Schema as S } from 'effect';\n\nimport { invariant } from '@dxos/invariant';\nimport { isNonNullable } from '@dxos/util';\n\nimport { type JsonPath, type JsonProp } from './jsonPath';\n\n//\n// Refs\n// https://effect.website/docs/schema/introduction\n// https://www.npmjs.com/package/@effect/schema\n// https://effect-ts.github.io/effect/schema/AST.ts.html\n//\n\nexport type SimpleType = 'object' | 'string' | 'number' | 'boolean' | 'enum' | 'literal';\n\n/**\n * Get the base type; e.g., traverse through refinements.\n */\nexport const getSimpleType = (node: AST.AST): SimpleType | undefined => {\n if (AST.isObjectKeyword(node) || AST.isTypeLiteral(node) || isDiscriminatedUnion(node) || AST.isDeclaration(node)) {\n return 'object';\n }\n\n if (AST.isStringKeyword(node)) {\n return 'string';\n }\n if (AST.isNumberKeyword(node)) {\n return 'number';\n }\n if (AST.isBooleanKeyword(node)) {\n return 'boolean';\n }\n\n if (AST.isEnums(node)) {\n return 'enum';\n }\n\n if (AST.isLiteral(node)) {\n return 'literal';\n }\n};\n\nexport const isSimpleType = (node: AST.AST): boolean => !!getSimpleType(node);\n\nexport namespace SimpleType {\n /**\n * Returns the default empty value for a given SimpleType.\n * Used for initializing new array values etc.\n */\n export const getDefaultValue = (type: SimpleType): any => {\n switch (type) {\n case 'string': {\n return '';\n }\n case 'number': {\n return 0;\n }\n case 'boolean': {\n return false;\n }\n case 'object': {\n return {};\n }\n default: {\n throw new Error(`Unsupported type for default value: ${type}`);\n }\n }\n };\n}\n\n//\n// Branded types\n//\n\nexport enum VisitResult {\n CONTINUE = 0,\n /**\n * Skip visiting children.\n */\n SKIP = 1,\n /**\n * Stop traversing immediately.\n */\n EXIT = 2,\n}\n\nexport type Path = (string | number)[];\n\nexport type TestFn = (node: AST.AST, path: Path, depth: number) => VisitResult | boolean | undefined;\n\nexport type VisitorFn = (node: AST.AST, path: Path, depth: number) => void;\n\nconst defaultTest: TestFn = isSimpleType;\n\n/**\n * Visit leaf nodes.\n * Refs:\n * - https://github.com/syntax-tree/unist-util-visit?tab=readme-ov-file#visitor\n * - https://github.com/syntax-tree/unist-util-is?tab=readme-ov-file#test\n */\nexport const visit: {\n (node: AST.AST, visitor: VisitorFn): void;\n (node: AST.AST, test: TestFn, visitor: VisitorFn): void;\n} = (node: AST.AST, testOrVisitor: TestFn | VisitorFn, visitor?: VisitorFn): void => {\n if (!visitor) {\n visitNode(node, defaultTest, testOrVisitor);\n } else {\n visitNode(node, testOrVisitor as TestFn, visitor);\n }\n};\n\nconst visitNode = (\n node: AST.AST,\n test: TestFn | undefined,\n visitor: VisitorFn,\n path: Path = [],\n depth = 0,\n): VisitResult | undefined => {\n const _result = test?.(node, path, depth);\n const result: VisitResult =\n _result === undefined\n ? VisitResult.CONTINUE\n : typeof _result === 'boolean'\n ? _result\n ? VisitResult.CONTINUE\n : VisitResult.SKIP\n : _result;\n\n if (result === VisitResult.EXIT) {\n return result;\n }\n if (result !== VisitResult.SKIP) {\n visitor(node, path, depth);\n }\n\n // Object.\n if (AST.isTypeLiteral(node)) {\n for (const prop of AST.getPropertySignatures(node)) {\n const currentPath = [...path, prop.name.toString()];\n const result = visitNode(prop.type, test, visitor, currentPath, depth + 1);\n if (result === VisitResult.EXIT) {\n return result;\n }\n }\n }\n\n // Array.\n else if (AST.isTupleType(node)) {\n for (const [i, element] of node.elements.entries()) {\n const currentPath = [...path, i];\n const result = visitNode(element.type, test, visitor, currentPath, depth);\n if (result === VisitResult.EXIT) {\n return result;\n }\n }\n }\n\n // Branching union (e.g., optional, discriminated unions).\n else if (AST.isUnion(node)) {\n for (const type of node.types) {\n const result = visitNode(type, test, visitor, path, depth);\n if (result === VisitResult.EXIT) {\n return result;\n }\n }\n }\n\n // Refinement.\n else if (AST.isRefinement(node)) {\n const result = visitNode(node.from, test, visitor, path, depth);\n if (result === VisitResult.EXIT) {\n return result;\n }\n }\n\n // TODO(burdon): Transforms?\n};\n\n/**\n * Recursively descend into AST to find first node that passes the test.\n */\n// TODO(burdon): Rewrite using visitNode?\nexport const findNode = (node: AST.AST, test: (node: AST.AST) => boolean): AST.AST | undefined => {\n if (test(node)) {\n return node;\n }\n\n // Object.\n else if (AST.isTypeLiteral(node)) {\n for (const prop of AST.getPropertySignatures(node)) {\n const child = findNode(prop.type, test);\n if (child) {\n return child;\n }\n }\n }\n\n // Tuple.\n else if (AST.isTupleType(node)) {\n for (const [_, element] of node.elements.entries()) {\n const child = findNode(element.type, test);\n if (child) {\n return child;\n }\n }\n }\n\n // Branching union (e.g., optional, discriminated unions).\n else if (AST.isUnion(node)) {\n if (isOption(node)) {\n for (const type of node.types) {\n const child = findNode(type, test);\n if (child) {\n return child;\n }\n }\n }\n }\n\n // Refinement.\n else if (AST.isRefinement(node)) {\n return findNode(node.from, test);\n }\n};\n\n/**\n * Get the AST node for the given property (dot-path).\n */\nexport const findProperty = (schema: S.Schema<any>, path: JsonPath | JsonProp): AST.AST | undefined => {\n const getProp = (node: AST.AST, path: JsonProp[]): AST.AST | undefined => {\n const [name, ...rest] = path;\n const typeNode = findNode(node, AST.isTypeLiteral);\n invariant(typeNode);\n for (const prop of AST.getPropertySignatures(typeNode)) {\n if (prop.name === name) {\n if (rest.length) {\n return getProp(prop.type, rest);\n } else {\n return prop.type;\n }\n }\n }\n };\n\n return getProp(schema.ast, path.split('.') as JsonProp[]);\n};\n\n//\n// Annotations\n//\n\nconst defaultAnnotations: Record<string, AST.Annotated> = {\n ['ObjectKeyword' as const]: AST.objectKeyword,\n ['StringKeyword' as const]: AST.stringKeyword,\n ['NumberKeyword' as const]: AST.numberKeyword,\n ['BooleanKeyword' as const]: AST.booleanKeyword,\n};\n\n/**\n * Get annotation or return undefined.\n * @param annotationId\n * @param noDefault If true, then return undefined for effect library defined values.\n */\nexport const getAnnotation =\n <T>(annotationId: symbol, noDefault = true) =>\n (node: AST.AST): T | undefined => {\n // Title fallback seems to be the identifier.\n const id = pipe(AST.getIdentifierAnnotation(node), Option.getOrUndefined);\n const value = pipe(AST.getAnnotation<T>(annotationId)(node), Option.getOrUndefined);\n if (noDefault && (value === defaultAnnotations[node._tag]?.annotations[annotationId] || value === id)) {\n return undefined;\n }\n\n return value;\n };\n\n/**\n * Recursively descend into AST to find first matching annotations.\n * Optionally skips default annotations for basic types (e.g., 'a string').\n */\n// TODO(burdon): Convert to effect pattern (i.e., return operator like getAnnotation).\nexport const findAnnotation = <T>(node: AST.AST, annotationId: symbol, noDefault = true): T | undefined => {\n const getAnnotationById = getAnnotation(annotationId, noDefault);\n\n const getBaseAnnotation = (node: AST.AST): T | undefined => {\n const value = getAnnotationById(node);\n if (value !== undefined) {\n return value as T;\n }\n\n if (AST.isUnion(node)) {\n if (isOption(node)) {\n return getAnnotationById(node.types[0]) as T;\n }\n }\n };\n\n return getBaseAnnotation(node);\n};\n\n//\n// Unions\n//\n\n/**\n * Effect S.optional creates a union type with undefined as the second type.\n */\nexport const isOption = (node: AST.AST): boolean => {\n return AST.isUnion(node) && node.types.length === 2 && AST.isUndefinedKeyword(node.types[1]);\n};\n\n/**\n * Determines if the node is a union of literal types.\n */\nexport const isLiteralUnion = (node: AST.AST): boolean => {\n return AST.isUnion(node) && node.types.every(AST.isLiteral);\n};\n\n/**\n * Determines if the node is a discriminated union.\n */\nexport const isDiscriminatedUnion = (node: AST.AST): boolean => {\n return AST.isUnion(node) && !!getDiscriminatingProps(node)?.length;\n};\n\n/**\n * Get the discriminating properties for the given union type.\n */\nexport const getDiscriminatingProps = (node: AST.AST): string[] | undefined => {\n invariant(AST.isUnion(node));\n if (isOption(node)) {\n return;\n }\n\n // Get common literals across all types.\n return node.types.reduce<string[]>((shared, type) => {\n const props = AST.getPropertySignatures(type)\n // TODO(burdon): Should check each literal is unique.\n .filter((p) => AST.isLiteral(p.type))\n .map((p) => p.name.toString());\n\n // Return common literals.\n return shared.length === 0 ? props : shared.filter((prop) => props.includes(prop));\n }, []);\n};\n\n/**\n * Get the discriminated type for the given value.\n */\nexport const getDiscriminatedType = (node: AST.AST, value: Record<string, any> = {}): AST.AST | undefined => {\n invariant(AST.isUnion(node));\n invariant(value);\n const props = getDiscriminatingProps(node);\n if (!props?.length) {\n return;\n }\n\n // Match provided values.\n for (const type of node.types) {\n const match = AST.getPropertySignatures(type)\n .filter((prop) => props?.includes(prop.name.toString()))\n .every((prop) => {\n invariant(AST.isLiteral(prop.type));\n return prop.type.literal === value[prop.name.toString()];\n });\n\n if (match) {\n return type;\n }\n }\n\n // Create union of discriminating properties.\n // NOTE: This may not work with non-overlapping variants.\n // TODO(burdon): Iterate through props and knock-out variants that don't match.\n const fields = Object.fromEntries(\n props\n .map((prop) => {\n const literals = node.types\n .map((type) => {\n const literal = AST.getPropertySignatures(type).find((p) => p.name.toString() === prop)!;\n invariant(AST.isLiteral(literal.type));\n return literal.type.literal;\n })\n .filter(isNonNullable);\n\n return literals.length ? [prop, S.Literal(...literals)] : undefined;\n })\n .filter(isNonNullable),\n );\n\n const schema = S.Struct(fields);\n return schema.ast;\n};\n\n/**\n * Maps AST nodes.\n * The user is responsible for recursively calling {@link mapAst} on the AST.\n * NOTE: Will evaluate suspended ASTs.\n */\nexport const mapAst = (ast: AST.AST, f: (ast: AST.AST, key: keyof any | undefined) => AST.AST): AST.AST => {\n switch (ast._tag) {\n case 'TypeLiteral':\n return new AST.TypeLiteral(\n ast.propertySignatures.map(\n (prop) =>\n new AST.PropertySignature(\n prop.name,\n f(prop.type, prop.name),\n prop.isOptional,\n prop.isReadonly,\n prop.annotations,\n ),\n ),\n ast.indexSignatures,\n );\n case 'Union':\n return AST.Union.make(ast.types.map(f), ast.annotations);\n case 'TupleType':\n return new AST.TupleType(\n ast.elements.map((t, index) => new AST.OptionalType(f(t.type, index), t.isOptional, t.annotations)),\n ast.rest.map((t) => new AST.Type(f(t.type, undefined), t.annotations)),\n ast.isReadonly,\n ast.annotations,\n );\n case 'Suspend': {\n const newAst = f(ast.f(), undefined);\n return new AST.Suspend(() => newAst, ast.annotations);\n }\n default:\n // TODO(dmaretskyi): Support more nodes.\n return ast;\n }\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Schema as S } from 'effect';\nimport { isSome } from 'effect/Option';\n\nimport { invariant } from '@dxos/invariant';\n\nexport type JsonProp = string & { __JsonPath: true; __JsonProp: true };\nexport type JsonPath = string & { __JsonPath: true };\n\nconst PATH_REGEX = /^($|[a-zA-Z_$][\\w$]*(?:\\.[a-zA-Z_$][\\w$]*|\\[\\d+\\](?:\\.)?)*$)/;\nconst PROP_REGEX = /\\w+/;\n\n/**\n * https://www.ietf.org/archive/id/draft-goessner-dispatch-jsonpath-00.html\n */\nexport const JsonPath = S.String.pipe(S.pattern(PATH_REGEX)) as any as S.Schema<JsonPath>;\nexport const JsonProp = S.NonEmptyString.pipe(S.pattern(PROP_REGEX)) as any as S.Schema<JsonProp>;\n\nexport const isJsonPath = (value: unknown): value is JsonPath => {\n return isSome(S.validateOption(JsonPath)(value));\n};\n\n/**\n * Creates a JsonPath from an array of path segments.\n *\n * Currently supports:\n * - Simple property access (e.g., 'foo.bar')\n * - Array indexing with non-negative integers (e.g., 'foo[0]')\n * - Identifiers starting with letters, underscore, or $ (e.g., '$foo', '_bar')\n * - Dot notation for nested properties (e.g., 'foo.bar.baz')\n *\n * Does not support (yet?).\n * - Recursive descent (..)\n * - Wildcards (*)\n * - Array slicing\n * - Filters\n * - Negative indices\n *\n * @param path Array of string or number segments\n * @returns Valid JsonPath or undefined if invalid\n */\nexport const createJsonPath = (path: (string | number)[]): JsonPath => {\n const candidatePath = path\n .map((p, i) => {\n if (typeof p === 'number') {\n return `[${p}]`;\n } else {\n return i === 0 ? p : `.${p}`;\n }\n })\n .join('');\n\n invariant(isJsonPath(candidatePath), `Invalid JsonPath: ${candidatePath}`);\n return candidatePath;\n};\n\n/**\n * Converts Effect validation path format (e.g. \"addresses.[0].zip\")\n * to JsonPath format (e.g. \"addresses[0].zip\")\n */\nexport const fromEffectValidationPath = (effectPath: string): JsonPath => {\n // Handle array notation: convert \"prop.[0]\" to \"prop[0]\"\n const jsonPath = effectPath.replace(/\\.\\[(\\d+)\\]/g, '[$1]');\n invariant(isJsonPath(jsonPath), `Invalid JsonPath: ${jsonPath}`);\n return jsonPath;\n};\n\n/**\n * Splits a JsonPath into its constituent parts.\n * Handles property access and array indexing.\n */\nexport const splitJsonPath = (path: JsonPath): string[] => {\n if (!isJsonPath(path)) {\n return [];\n }\n\n return (\n path\n .match(/[a-zA-Z_$][\\w$]*|\\[\\d+\\]/g)\n ?.map((part) => (part.startsWith('[') ? part.replace(/[[\\]]/g, '') : part)) ?? []\n );\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { SchemaAST as AST, type Schema as S, Option, pipe } from 'effect';\n\nimport { decamelize } from '@dxos/util';\n\nconst ParamKeyAnnotationId = Symbol.for('@dxos/schema/annotation/ParamKey');\n\ntype ParamKeyAnnotationValue = { key: string };\n\nexport const getParamKeyAnnotation: (annotated: AST.Annotated) => Option.Option<ParamKeyAnnotationValue> =\n AST.getAnnotation<ParamKeyAnnotationValue>(ParamKeyAnnotationId);\n\nexport const ParamKeyAnnotation =\n (value: ParamKeyAnnotationValue) =>\n <S extends S.Annotable.All>(self: S): S.Annotable.Self<S> =>\n self.annotations({ [ParamKeyAnnotationId]: value });\n\n/**\n * HTTP params parser.\n * Supports custom key serialization.\n */\nexport class UrlParser<T extends Record<string, any>> {\n constructor(private readonly _schema: S.Struct<T>) {}\n\n /**\n * Parse URL params.\n */\n parse(_url: string): T {\n const url = new URL(_url);\n return Object.entries(this._schema.fields).reduce<Record<string, any>>((params, [key, type]) => {\n let value = url.searchParams.get(decamelize(key));\n if (value == null) {\n value = url.searchParams.get(key);\n }\n\n if (value != null) {\n if (AST.isNumberKeyword(type.ast)) {\n params[key] = parseInt(value);\n } else if (AST.isBooleanKeyword(type.ast)) {\n params[key] = value === 'true' || value === '1';\n } else {\n params[key] = value;\n }\n }\n\n return params;\n }, {}) as T;\n }\n\n /**\n * Return URL with encoded params.\n */\n create(_url: string, params: T): URL {\n const url = new URL(_url);\n Object.entries(params).forEach(([key, value]) => {\n if (value !== undefined) {\n const field = this._schema.fields[key];\n if (field) {\n const { key: serializedKey } = pipe(\n getParamKeyAnnotation(field.ast),\n Option.getOrElse(() => ({\n key: decamelize(key),\n })),\n );\n\n url.searchParams.set(serializedKey, String(value));\n }\n }\n });\n\n return url;\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;AAIA,SAASA,QAAQC,MAAMC,aAAaC,KAAKC,UAAUC,SAAS;AAE5D,SAASC,iBAAiB;AAC1B,SAASC,qBAAqB;;AAgBvB,IAAMC,gBAAgB,CAACC,SAAAA;AAC5B,MAAIN,IAAIO,gBAAgBD,IAAAA,KAASN,IAAIQ,cAAcF,IAAAA,KAASG,qBAAqBH,IAAAA,KAASN,IAAIU,cAAcJ,IAAAA,GAAO;AACjH,WAAO;EACT;AAEA,MAAIN,IAAIW,gBAAgBL,IAAAA,GAAO;AAC7B,WAAO;EACT;AACA,MAAIN,IAAIY,gBAAgBN,IAAAA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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": ["Option", "pipe", "SchemaAST", "AST", "Schema", "S", "invariant", "isNonNullable", "getSimpleType", "node", "isObjectKeyword", "isTypeLiteral", "isDiscriminatedUnion", "isDeclaration", "isStringKeyword", "isNumberKeyword", "isBooleanKeyword", "isEnums", "isLiteral", "isSimpleType", "SimpleType", "getDefaultValue", "type", "Error", "VisitResult", "defaultTest", "visit", "testOrVisitor", "visitor", "visitNode", "test", "path", "depth", "_result", "result", "undefined", "prop", "getPropertySignatures", "currentPath", "name", "toString", "isTupleType", "i", "element", "elements", "entries", "isUnion", "types", "isRefinement", "from", "findNode", "child", "_", "isOption", "findProperty", "schema", "getProp", "rest", "typeNode", "length", "ast", "split", "defaultAnnotations", "objectKeyword", "stringKeyword", "numberKeyword", "booleanKeyword", "getAnnotation", "annotationId", "noDefault", "id", "getIdentifierAnnotation", "getOrUndefined", "value", "_tag", "annotations", "findAnnotation", "getAnnotationById", "getBaseAnnotation", "isUndefinedKeyword", "isLiteralUnion", "every", "getDiscriminatingProps", "reduce", "shared", "props", "filter", "p", "map", "includes", "getDiscriminatedType", "match", "literal", "fields", "Object", "fromEntries", "literals", "find", "Literal", "Struct", "mapAst", "f", "TypeLiteral", "propertySignatures", "PropertySignature", "isOptional", "isReadonly", "indexSignatures", "Union", "make", "TupleType", "t", "index", "OptionalType", "Type", "newAst", "Suspend", "Schema", "S", "isSome", "invariant", "PATH_REGEX", "PROP_REGEX", "JsonPath", "String", "pipe", "pattern", "JsonProp", "NonEmptyString", "isJsonPath", "value", "validateOption", "createJsonPath", "path", "candidatePath", "map", "p", "i", "join", "fromEffectValidationPath", "effectPath", "jsonPath", "replace", "splitJsonPath", "match", "part", "startsWith", "SchemaAST", "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":
|
|
1
|
+
{"inputs":{"packages/common/effect/src/ast.ts":{"bytes":40548,"imports":[{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/effect/src/jsonPath.ts":{"bytes":8432,"imports":[{"path":"effect","kind":"import-statement","external":true},{"path":"effect/Option","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true}],"format":"esm"},"packages/common/effect/src/url.ts":{"bytes":7659,"imports":[{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/effect/src/index.ts":{"bytes":648,"imports":[{"path":"packages/common/effect/src/ast.ts","kind":"import-statement","original":"./ast"},{"path":"packages/common/effect/src/jsonPath.ts","kind":"import-statement","original":"./jsonPath"},{"path":"packages/common/effect/src/url.ts","kind":"import-statement","original":"./url"}],"format":"esm"}},"outputs":{"packages/common/effect/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":28643},"packages/common/effect/dist/lib/browser/index.mjs":{"imports":[{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"effect/Option","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["JsonPath","JsonProp","ParamKeyAnnotation","SimpleType","UrlParser","VisitResult","createJsonPath","findAnnotation","findNode","findProperty","fromEffectValidationPath","getAnnotation","getDiscriminatedType","getDiscriminatingProps","getParamKeyAnnotation","getSimpleType","isDiscriminatedUnion","isJsonPath","isLiteralUnion","isOption","isSimpleType","mapAst","splitJsonPath","visit"],"entryPoint":"packages/common/effect/src/index.ts","inputs":{"packages/common/effect/src/ast.ts":{"bytesInOutput":8495},"packages/common/effect/src/index.ts":{"bytesInOutput":0},"packages/common/effect/src/jsonPath.ts":{"bytesInOutput":1550},"packages/common/effect/src/url.ts":{"bytesInOutput":1597}},"bytes":12249}}}
|
package/dist/lib/node/index.cjs
CHANGED
|
@@ -18,12 +18,9 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var node_exports = {};
|
|
20
20
|
__export(node_exports, {
|
|
21
|
-
AST: () => import_schema.AST,
|
|
22
|
-
JSONSchema: () => import_schema.JSONSchema,
|
|
23
21
|
JsonPath: () => JsonPath,
|
|
24
22
|
JsonProp: () => JsonProp,
|
|
25
23
|
ParamKeyAnnotation: () => ParamKeyAnnotation,
|
|
26
|
-
S: () => import_schema.Schema,
|
|
27
24
|
SimpleType: () => SimpleType,
|
|
28
25
|
UrlParser: () => UrlParser,
|
|
29
26
|
VisitResult: () => VisitResult,
|
|
@@ -47,35 +44,32 @@ __export(node_exports, {
|
|
|
47
44
|
visit: () => visit
|
|
48
45
|
});
|
|
49
46
|
module.exports = __toCommonJS(node_exports);
|
|
50
|
-
var import_schema = require("@effect/schema");
|
|
51
|
-
var import_schema2 = require("@effect/schema");
|
|
52
47
|
var import_effect = require("effect");
|
|
53
48
|
var import_invariant = require("@dxos/invariant");
|
|
54
49
|
var import_util = require("@dxos/util");
|
|
55
|
-
var
|
|
50
|
+
var import_effect2 = require("effect");
|
|
56
51
|
var import_Option = require("effect/Option");
|
|
57
52
|
var import_invariant2 = require("@dxos/invariant");
|
|
58
|
-
var
|
|
59
|
-
var import_effect2 = require("effect");
|
|
53
|
+
var import_effect3 = require("effect");
|
|
60
54
|
var import_util2 = require("@dxos/util");
|
|
61
55
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/common/effect/src/ast.ts";
|
|
62
56
|
var getSimpleType = (node) => {
|
|
63
|
-
if (
|
|
57
|
+
if (import_effect.SchemaAST.isObjectKeyword(node) || import_effect.SchemaAST.isTypeLiteral(node) || isDiscriminatedUnion(node) || import_effect.SchemaAST.isDeclaration(node)) {
|
|
64
58
|
return "object";
|
|
65
59
|
}
|
|
66
|
-
if (
|
|
60
|
+
if (import_effect.SchemaAST.isStringKeyword(node)) {
|
|
67
61
|
return "string";
|
|
68
62
|
}
|
|
69
|
-
if (
|
|
63
|
+
if (import_effect.SchemaAST.isNumberKeyword(node)) {
|
|
70
64
|
return "number";
|
|
71
65
|
}
|
|
72
|
-
if (
|
|
66
|
+
if (import_effect.SchemaAST.isBooleanKeyword(node)) {
|
|
73
67
|
return "boolean";
|
|
74
68
|
}
|
|
75
|
-
if (
|
|
69
|
+
if (import_effect.SchemaAST.isEnums(node)) {
|
|
76
70
|
return "enum";
|
|
77
71
|
}
|
|
78
|
-
if (
|
|
72
|
+
if (import_effect.SchemaAST.isLiteral(node)) {
|
|
79
73
|
return "literal";
|
|
80
74
|
}
|
|
81
75
|
};
|
|
@@ -125,8 +119,8 @@ var visitNode = (node, test, visitor, path = [], depth = 0) => {
|
|
|
125
119
|
if (result !== 1) {
|
|
126
120
|
visitor(node, path, depth);
|
|
127
121
|
}
|
|
128
|
-
if (
|
|
129
|
-
for (const prop of
|
|
122
|
+
if (import_effect.SchemaAST.isTypeLiteral(node)) {
|
|
123
|
+
for (const prop of import_effect.SchemaAST.getPropertySignatures(node)) {
|
|
130
124
|
const currentPath = [
|
|
131
125
|
...path,
|
|
132
126
|
prop.name.toString()
|
|
@@ -136,7 +130,7 @@ var visitNode = (node, test, visitor, path = [], depth = 0) => {
|
|
|
136
130
|
return result2;
|
|
137
131
|
}
|
|
138
132
|
}
|
|
139
|
-
} else if (
|
|
133
|
+
} else if (import_effect.SchemaAST.isTupleType(node)) {
|
|
140
134
|
for (const [i, element] of node.elements.entries()) {
|
|
141
135
|
const currentPath = [
|
|
142
136
|
...path,
|
|
@@ -147,14 +141,14 @@ var visitNode = (node, test, visitor, path = [], depth = 0) => {
|
|
|
147
141
|
return result2;
|
|
148
142
|
}
|
|
149
143
|
}
|
|
150
|
-
} else if (
|
|
144
|
+
} else if (import_effect.SchemaAST.isUnion(node)) {
|
|
151
145
|
for (const type of node.types) {
|
|
152
146
|
const result2 = visitNode(type, test, visitor, path, depth);
|
|
153
147
|
if (result2 === 2) {
|
|
154
148
|
return result2;
|
|
155
149
|
}
|
|
156
150
|
}
|
|
157
|
-
} else if (
|
|
151
|
+
} else if (import_effect.SchemaAST.isRefinement(node)) {
|
|
158
152
|
const result2 = visitNode(node.from, test, visitor, path, depth);
|
|
159
153
|
if (result2 === 2) {
|
|
160
154
|
return result2;
|
|
@@ -164,21 +158,21 @@ var visitNode = (node, test, visitor, path = [], depth = 0) => {
|
|
|
164
158
|
var findNode = (node, test) => {
|
|
165
159
|
if (test(node)) {
|
|
166
160
|
return node;
|
|
167
|
-
} else if (
|
|
168
|
-
for (const prop of
|
|
161
|
+
} else if (import_effect.SchemaAST.isTypeLiteral(node)) {
|
|
162
|
+
for (const prop of import_effect.SchemaAST.getPropertySignatures(node)) {
|
|
169
163
|
const child = findNode(prop.type, test);
|
|
170
164
|
if (child) {
|
|
171
165
|
return child;
|
|
172
166
|
}
|
|
173
167
|
}
|
|
174
|
-
} else if (
|
|
168
|
+
} else if (import_effect.SchemaAST.isTupleType(node)) {
|
|
175
169
|
for (const [_, element] of node.elements.entries()) {
|
|
176
170
|
const child = findNode(element.type, test);
|
|
177
171
|
if (child) {
|
|
178
172
|
return child;
|
|
179
173
|
}
|
|
180
174
|
}
|
|
181
|
-
} else if (
|
|
175
|
+
} else if (import_effect.SchemaAST.isUnion(node)) {
|
|
182
176
|
if (isOption(node)) {
|
|
183
177
|
for (const type of node.types) {
|
|
184
178
|
const child = findNode(type, test);
|
|
@@ -187,24 +181,24 @@ var findNode = (node, test) => {
|
|
|
187
181
|
}
|
|
188
182
|
}
|
|
189
183
|
}
|
|
190
|
-
} else if (
|
|
184
|
+
} else if (import_effect.SchemaAST.isRefinement(node)) {
|
|
191
185
|
return findNode(node.from, test);
|
|
192
186
|
}
|
|
193
187
|
};
|
|
194
188
|
var findProperty = (schema, path) => {
|
|
195
189
|
const getProp = (node, path2) => {
|
|
196
190
|
const [name, ...rest] = path2;
|
|
197
|
-
const typeNode = findNode(node,
|
|
191
|
+
const typeNode = findNode(node, import_effect.SchemaAST.isTypeLiteral);
|
|
198
192
|
(0, import_invariant.invariant)(typeNode, void 0, {
|
|
199
193
|
F: __dxlog_file,
|
|
200
|
-
L:
|
|
194
|
+
L: 238,
|
|
201
195
|
S: void 0,
|
|
202
196
|
A: [
|
|
203
197
|
"typeNode",
|
|
204
198
|
""
|
|
205
199
|
]
|
|
206
200
|
});
|
|
207
|
-
for (const prop of
|
|
201
|
+
for (const prop of import_effect.SchemaAST.getPropertySignatures(typeNode)) {
|
|
208
202
|
if (prop.name === name) {
|
|
209
203
|
if (rest.length) {
|
|
210
204
|
return getProp(prop.type, rest);
|
|
@@ -217,14 +211,14 @@ var findProperty = (schema, path) => {
|
|
|
217
211
|
return getProp(schema.ast, path.split("."));
|
|
218
212
|
};
|
|
219
213
|
var defaultAnnotations = {
|
|
220
|
-
["ObjectKeyword"]:
|
|
221
|
-
["StringKeyword"]:
|
|
222
|
-
["NumberKeyword"]:
|
|
223
|
-
["BooleanKeyword"]:
|
|
214
|
+
["ObjectKeyword"]: import_effect.SchemaAST.objectKeyword,
|
|
215
|
+
["StringKeyword"]: import_effect.SchemaAST.stringKeyword,
|
|
216
|
+
["NumberKeyword"]: import_effect.SchemaAST.numberKeyword,
|
|
217
|
+
["BooleanKeyword"]: import_effect.SchemaAST.booleanKeyword
|
|
224
218
|
};
|
|
225
219
|
var getAnnotation = (annotationId, noDefault = true) => (node) => {
|
|
226
|
-
const id = (0, import_effect.pipe)(
|
|
227
|
-
const value = (0, import_effect.pipe)(
|
|
220
|
+
const id = (0, import_effect.pipe)(import_effect.SchemaAST.getIdentifierAnnotation(node), import_effect.Option.getOrUndefined);
|
|
221
|
+
const value = (0, import_effect.pipe)(import_effect.SchemaAST.getAnnotation(annotationId)(node), import_effect.Option.getOrUndefined);
|
|
228
222
|
if (noDefault && (value === defaultAnnotations[node._tag]?.annotations[annotationId] || value === id)) {
|
|
229
223
|
return void 0;
|
|
230
224
|
}
|
|
@@ -237,7 +231,7 @@ var findAnnotation = (node, annotationId, noDefault = true) => {
|
|
|
237
231
|
if (value !== void 0) {
|
|
238
232
|
return value;
|
|
239
233
|
}
|
|
240
|
-
if (
|
|
234
|
+
if (import_effect.SchemaAST.isUnion(node2)) {
|
|
241
235
|
if (isOption(node2)) {
|
|
242
236
|
return getAnnotationById(node2.types[0]);
|
|
243
237
|
}
|
|
@@ -246,18 +240,18 @@ var findAnnotation = (node, annotationId, noDefault = true) => {
|
|
|
246
240
|
return getBaseAnnotation(node);
|
|
247
241
|
};
|
|
248
242
|
var isOption = (node) => {
|
|
249
|
-
return
|
|
243
|
+
return import_effect.SchemaAST.isUnion(node) && node.types.length === 2 && import_effect.SchemaAST.isUndefinedKeyword(node.types[1]);
|
|
250
244
|
};
|
|
251
245
|
var isLiteralUnion = (node) => {
|
|
252
|
-
return
|
|
246
|
+
return import_effect.SchemaAST.isUnion(node) && node.types.every(import_effect.SchemaAST.isLiteral);
|
|
253
247
|
};
|
|
254
248
|
var isDiscriminatedUnion = (node) => {
|
|
255
|
-
return
|
|
249
|
+
return import_effect.SchemaAST.isUnion(node) && !!getDiscriminatingProps(node)?.length;
|
|
256
250
|
};
|
|
257
251
|
var getDiscriminatingProps = (node) => {
|
|
258
|
-
(0, import_invariant.invariant)(
|
|
252
|
+
(0, import_invariant.invariant)(import_effect.SchemaAST.isUnion(node), void 0, {
|
|
259
253
|
F: __dxlog_file,
|
|
260
|
-
L:
|
|
254
|
+
L: 335,
|
|
261
255
|
S: void 0,
|
|
262
256
|
A: [
|
|
263
257
|
"AST.isUnion(node)",
|
|
@@ -268,14 +262,14 @@ var getDiscriminatingProps = (node) => {
|
|
|
268
262
|
return;
|
|
269
263
|
}
|
|
270
264
|
return node.types.reduce((shared, type) => {
|
|
271
|
-
const props =
|
|
265
|
+
const props = import_effect.SchemaAST.getPropertySignatures(type).filter((p) => import_effect.SchemaAST.isLiteral(p.type)).map((p) => p.name.toString());
|
|
272
266
|
return shared.length === 0 ? props : shared.filter((prop) => props.includes(prop));
|
|
273
267
|
}, []);
|
|
274
268
|
};
|
|
275
269
|
var getDiscriminatedType = (node, value = {}) => {
|
|
276
|
-
(0, import_invariant.invariant)(
|
|
270
|
+
(0, import_invariant.invariant)(import_effect.SchemaAST.isUnion(node), void 0, {
|
|
277
271
|
F: __dxlog_file,
|
|
278
|
-
L:
|
|
272
|
+
L: 356,
|
|
279
273
|
S: void 0,
|
|
280
274
|
A: [
|
|
281
275
|
"AST.isUnion(node)",
|
|
@@ -284,7 +278,7 @@ var getDiscriminatedType = (node, value = {}) => {
|
|
|
284
278
|
});
|
|
285
279
|
(0, import_invariant.invariant)(value, void 0, {
|
|
286
280
|
F: __dxlog_file,
|
|
287
|
-
L:
|
|
281
|
+
L: 357,
|
|
288
282
|
S: void 0,
|
|
289
283
|
A: [
|
|
290
284
|
"value",
|
|
@@ -296,10 +290,10 @@ var getDiscriminatedType = (node, value = {}) => {
|
|
|
296
290
|
return;
|
|
297
291
|
}
|
|
298
292
|
for (const type of node.types) {
|
|
299
|
-
const match =
|
|
300
|
-
(0, import_invariant.invariant)(
|
|
293
|
+
const match = import_effect.SchemaAST.getPropertySignatures(type).filter((prop) => props?.includes(prop.name.toString())).every((prop) => {
|
|
294
|
+
(0, import_invariant.invariant)(import_effect.SchemaAST.isLiteral(prop.type), void 0, {
|
|
301
295
|
F: __dxlog_file,
|
|
302
|
-
L:
|
|
296
|
+
L: 368,
|
|
303
297
|
S: void 0,
|
|
304
298
|
A: [
|
|
305
299
|
"AST.isLiteral(prop.type)",
|
|
@@ -314,10 +308,10 @@ var getDiscriminatedType = (node, value = {}) => {
|
|
|
314
308
|
}
|
|
315
309
|
const fields = Object.fromEntries(props.map((prop) => {
|
|
316
310
|
const literals = node.types.map((type) => {
|
|
317
|
-
const literal =
|
|
318
|
-
(0, import_invariant.invariant)(
|
|
311
|
+
const literal = import_effect.SchemaAST.getPropertySignatures(type).find((p) => p.name.toString() === prop);
|
|
312
|
+
(0, import_invariant.invariant)(import_effect.SchemaAST.isLiteral(literal.type), void 0, {
|
|
319
313
|
F: __dxlog_file,
|
|
320
|
-
L:
|
|
314
|
+
L: 386,
|
|
321
315
|
S: void 0,
|
|
322
316
|
A: [
|
|
323
317
|
"AST.isLiteral(literal.type)",
|
|
@@ -328,23 +322,23 @@ var getDiscriminatedType = (node, value = {}) => {
|
|
|
328
322
|
}).filter(import_util.isNonNullable);
|
|
329
323
|
return literals.length ? [
|
|
330
324
|
prop,
|
|
331
|
-
|
|
325
|
+
import_effect.Schema.Literal(...literals)
|
|
332
326
|
] : void 0;
|
|
333
327
|
}).filter(import_util.isNonNullable));
|
|
334
|
-
const schema =
|
|
328
|
+
const schema = import_effect.Schema.Struct(fields);
|
|
335
329
|
return schema.ast;
|
|
336
330
|
};
|
|
337
331
|
var mapAst = (ast, f) => {
|
|
338
332
|
switch (ast._tag) {
|
|
339
333
|
case "TypeLiteral":
|
|
340
|
-
return new
|
|
334
|
+
return new import_effect.SchemaAST.TypeLiteral(ast.propertySignatures.map((prop) => new import_effect.SchemaAST.PropertySignature(prop.name, f(prop.type, prop.name), prop.isOptional, prop.isReadonly, prop.annotations)), ast.indexSignatures);
|
|
341
335
|
case "Union":
|
|
342
|
-
return
|
|
336
|
+
return import_effect.SchemaAST.Union.make(ast.types.map(f), ast.annotations);
|
|
343
337
|
case "TupleType":
|
|
344
|
-
return new
|
|
338
|
+
return new import_effect.SchemaAST.TupleType(ast.elements.map((t, index) => new import_effect.SchemaAST.OptionalType(f(t.type, index), t.isOptional, t.annotations)), ast.rest.map((t) => new import_effect.SchemaAST.Type(f(t.type, void 0), t.annotations)), ast.isReadonly, ast.annotations);
|
|
345
339
|
case "Suspend": {
|
|
346
340
|
const newAst = f(ast.f(), void 0);
|
|
347
|
-
return new
|
|
341
|
+
return new import_effect.SchemaAST.Suspend(() => newAst, ast.annotations);
|
|
348
342
|
}
|
|
349
343
|
default:
|
|
350
344
|
return ast;
|
|
@@ -353,10 +347,10 @@ var mapAst = (ast, f) => {
|
|
|
353
347
|
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/common/effect/src/jsonPath.ts";
|
|
354
348
|
var PATH_REGEX = /^($|[a-zA-Z_$][\w$]*(?:\.[a-zA-Z_$][\w$]*|\[\d+\](?:\.)?)*$)/;
|
|
355
349
|
var PROP_REGEX = /\w+/;
|
|
356
|
-
var JsonPath =
|
|
357
|
-
var JsonProp =
|
|
350
|
+
var JsonPath = import_effect2.Schema.String.pipe(import_effect2.Schema.pattern(PATH_REGEX));
|
|
351
|
+
var JsonProp = import_effect2.Schema.NonEmptyString.pipe(import_effect2.Schema.pattern(PROP_REGEX));
|
|
358
352
|
var isJsonPath = (value) => {
|
|
359
|
-
return (0, import_Option.isSome)(
|
|
353
|
+
return (0, import_Option.isSome)(import_effect2.Schema.validateOption(JsonPath)(value));
|
|
360
354
|
};
|
|
361
355
|
var createJsonPath = (path) => {
|
|
362
356
|
const candidatePath = path.map((p, i) => {
|
|
@@ -397,7 +391,7 @@ var splitJsonPath = (path) => {
|
|
|
397
391
|
return path.match(/[a-zA-Z_$][\w$]*|\[\d+\]/g)?.map((part) => part.startsWith("[") ? part.replace(/[[\]]/g, "") : part) ?? [];
|
|
398
392
|
};
|
|
399
393
|
var ParamKeyAnnotationId = Symbol.for("@dxos/schema/annotation/ParamKey");
|
|
400
|
-
var getParamKeyAnnotation =
|
|
394
|
+
var getParamKeyAnnotation = import_effect3.SchemaAST.getAnnotation(ParamKeyAnnotationId);
|
|
401
395
|
var ParamKeyAnnotation = (value) => (self) => self.annotations({
|
|
402
396
|
[ParamKeyAnnotationId]: value
|
|
403
397
|
});
|
|
@@ -416,9 +410,9 @@ var UrlParser = class {
|
|
|
416
410
|
value = url.searchParams.get(key);
|
|
417
411
|
}
|
|
418
412
|
if (value != null) {
|
|
419
|
-
if (
|
|
413
|
+
if (import_effect3.SchemaAST.isNumberKeyword(type.ast)) {
|
|
420
414
|
params[key] = parseInt(value);
|
|
421
|
-
} else if (
|
|
415
|
+
} else if (import_effect3.SchemaAST.isBooleanKeyword(type.ast)) {
|
|
422
416
|
params[key] = value === "true" || value === "1";
|
|
423
417
|
} else {
|
|
424
418
|
params[key] = value;
|
|
@@ -436,7 +430,7 @@ var UrlParser = class {
|
|
|
436
430
|
if (value !== void 0) {
|
|
437
431
|
const field = this._schema.fields[key];
|
|
438
432
|
if (field) {
|
|
439
|
-
const { key: serializedKey } = (0,
|
|
433
|
+
const { key: serializedKey } = (0, import_effect3.pipe)(getParamKeyAnnotation(field.ast), import_effect3.Option.getOrElse(() => ({
|
|
440
434
|
key: (0, import_util2.decamelize)(key)
|
|
441
435
|
})));
|
|
442
436
|
url.searchParams.set(serializedKey, String(value));
|
|
@@ -448,12 +442,9 @@ var UrlParser = class {
|
|
|
448
442
|
};
|
|
449
443
|
// Annotate the CommonJS export names for ESM import in node:
|
|
450
444
|
0 && (module.exports = {
|
|
451
|
-
AST,
|
|
452
|
-
JSONSchema,
|
|
453
445
|
JsonPath,
|
|
454
446
|
JsonProp,
|
|
455
447
|
ParamKeyAnnotation,
|
|
456
|
-
S,
|
|
457
448
|
SimpleType,
|
|
458
449
|
UrlParser,
|
|
459
450
|
VisitResult,
|