@dxos/effect 0.7.4 → 0.7.5-labs.071a3e2
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 +67 -16
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +70 -17
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +67 -16
- 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 +2 -13
- package/dist/types/src/ast.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/jsonPath.d.ts +45 -0
- package/dist/types/src/jsonPath.d.ts.map +1 -0
- package/dist/types/src/jsonPath.test.d.ts +2 -0
- package/dist/types/src/jsonPath.test.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +7 -7
- package/src/ast.test.ts +1 -2
- package/src/ast.ts +14 -18
- package/src/index.ts +1 -0
- package/src/jsonPath.test.ts +96 -0
- package/src/jsonPath.ts +85 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "@dxos/node-std/globals";
|
|
2
2
|
|
|
3
3
|
// packages/common/effect/src/index.ts
|
|
4
|
-
import { AST as AST3, JSONSchema, Schema as
|
|
4
|
+
import { AST as AST3, JSONSchema, Schema as S3 } from "@effect/schema";
|
|
5
5
|
|
|
6
6
|
// packages/common/effect/src/ast.ts
|
|
7
7
|
import { AST, Schema as S } from "@effect/schema";
|
|
@@ -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,10 +52,6 @@ var SimpleType;
|
|
|
52
52
|
}
|
|
53
53
|
};
|
|
54
54
|
})(SimpleType || (SimpleType = {}));
|
|
55
|
-
var PATH_REGEX = /[a-zA-Z_$][\w$]*(?:\.[a-zA-Z_$][\w$]*)*/;
|
|
56
|
-
var PROP_REGEX = /\w+/;
|
|
57
|
-
var JsonPath = S.NonEmptyString.pipe(S.pattern(PATH_REGEX));
|
|
58
|
-
var JsonProp = S.NonEmptyString.pipe(S.pattern(PROP_REGEX));
|
|
59
55
|
var VisitResult;
|
|
60
56
|
(function(VisitResult2) {
|
|
61
57
|
VisitResult2[VisitResult2["CONTINUE"] = 0] = "CONTINUE";
|
|
@@ -151,7 +147,7 @@ var findProperty = (schema, path) => {
|
|
|
151
147
|
const typeNode = findNode(node, AST.isTypeLiteral);
|
|
152
148
|
invariant(typeNode, void 0, {
|
|
153
149
|
F: __dxlog_file,
|
|
154
|
-
L:
|
|
150
|
+
L: 239,
|
|
155
151
|
S: void 0,
|
|
156
152
|
A: [
|
|
157
153
|
"typeNode",
|
|
@@ -211,7 +207,7 @@ var isDiscriminatedUnion = (node) => {
|
|
|
211
207
|
var getDiscriminatingProps = (node) => {
|
|
212
208
|
invariant(AST.isUnion(node), void 0, {
|
|
213
209
|
F: __dxlog_file,
|
|
214
|
-
L:
|
|
210
|
+
L: 336,
|
|
215
211
|
S: void 0,
|
|
216
212
|
A: [
|
|
217
213
|
"AST.isUnion(node)",
|
|
@@ -229,7 +225,7 @@ var getDiscriminatingProps = (node) => {
|
|
|
229
225
|
var getDiscriminatedType = (node, value = {}) => {
|
|
230
226
|
invariant(AST.isUnion(node), void 0, {
|
|
231
227
|
F: __dxlog_file,
|
|
232
|
-
L:
|
|
228
|
+
L: 357,
|
|
233
229
|
S: void 0,
|
|
234
230
|
A: [
|
|
235
231
|
"AST.isUnion(node)",
|
|
@@ -238,7 +234,7 @@ var getDiscriminatedType = (node, value = {}) => {
|
|
|
238
234
|
});
|
|
239
235
|
invariant(value, void 0, {
|
|
240
236
|
F: __dxlog_file,
|
|
241
|
-
L:
|
|
237
|
+
L: 358,
|
|
242
238
|
S: void 0,
|
|
243
239
|
A: [
|
|
244
240
|
"value",
|
|
@@ -253,7 +249,7 @@ var getDiscriminatedType = (node, value = {}) => {
|
|
|
253
249
|
const match = AST.getPropertySignatures(type).filter((prop) => props?.includes(prop.name.toString())).every((prop) => {
|
|
254
250
|
invariant(AST.isLiteral(prop.type), void 0, {
|
|
255
251
|
F: __dxlog_file,
|
|
256
|
-
L:
|
|
252
|
+
L: 369,
|
|
257
253
|
S: void 0,
|
|
258
254
|
A: [
|
|
259
255
|
"AST.isLiteral(prop.type)",
|
|
@@ -271,7 +267,7 @@ var getDiscriminatedType = (node, value = {}) => {
|
|
|
271
267
|
const literal = AST.getPropertySignatures(type).find((p) => p.name.toString() === prop);
|
|
272
268
|
invariant(AST.isLiteral(literal.type), void 0, {
|
|
273
269
|
F: __dxlog_file,
|
|
274
|
-
L:
|
|
270
|
+
L: 387,
|
|
275
271
|
S: void 0,
|
|
276
272
|
A: [
|
|
277
273
|
"AST.isLiteral(literal.type)",
|
|
@@ -291,13 +287,13 @@ var getDiscriminatedType = (node, value = {}) => {
|
|
|
291
287
|
var mapAst = (ast, f) => {
|
|
292
288
|
switch (ast._tag) {
|
|
293
289
|
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);
|
|
290
|
+
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
291
|
case "Union":
|
|
296
292
|
return AST.Union.make(ast.types.map(f), ast.annotations);
|
|
297
293
|
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);
|
|
294
|
+
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
295
|
case "Suspend": {
|
|
300
|
-
const newAst = f(ast.f());
|
|
296
|
+
const newAst = f(ast.f(), void 0);
|
|
301
297
|
return new AST.Suspend(() => newAst, ast.annotations);
|
|
302
298
|
}
|
|
303
299
|
default:
|
|
@@ -305,6 +301,57 @@ var mapAst = (ast, f) => {
|
|
|
305
301
|
}
|
|
306
302
|
};
|
|
307
303
|
|
|
304
|
+
// packages/common/effect/src/jsonPath.ts
|
|
305
|
+
import { Schema as S2 } from "@effect/schema";
|
|
306
|
+
import { isSome } from "effect/Option";
|
|
307
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
308
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/common/effect/src/jsonPath.ts";
|
|
309
|
+
var PATH_REGEX = /^($|[a-zA-Z_$][\w$]*(?:\.[a-zA-Z_$][\w$]*|\[\d+\](?:\.)?)*$)/;
|
|
310
|
+
var PROP_REGEX = /\w+/;
|
|
311
|
+
var JsonPath = S2.String.pipe(S2.pattern(PATH_REGEX));
|
|
312
|
+
var JsonProp = S2.NonEmptyString.pipe(S2.pattern(PROP_REGEX));
|
|
313
|
+
var isJsonPath = (value) => {
|
|
314
|
+
return isSome(S2.validateOption(JsonPath)(value));
|
|
315
|
+
};
|
|
316
|
+
var createJsonPath = (path) => {
|
|
317
|
+
const candidatePath = path.map((p, i) => {
|
|
318
|
+
if (typeof p === "number") {
|
|
319
|
+
return `[${p}]`;
|
|
320
|
+
} else {
|
|
321
|
+
return i === 0 ? p : `.${p}`;
|
|
322
|
+
}
|
|
323
|
+
}).join("");
|
|
324
|
+
invariant2(isJsonPath(candidatePath), `Invalid JsonPath: ${candidatePath}`, {
|
|
325
|
+
F: __dxlog_file2,
|
|
326
|
+
L: 56,
|
|
327
|
+
S: void 0,
|
|
328
|
+
A: [
|
|
329
|
+
"isJsonPath(candidatePath)",
|
|
330
|
+
"`Invalid JsonPath: ${candidatePath}`"
|
|
331
|
+
]
|
|
332
|
+
});
|
|
333
|
+
return candidatePath;
|
|
334
|
+
};
|
|
335
|
+
var fromEffectValidationPath = (effectPath) => {
|
|
336
|
+
const jsonPath = effectPath.replace(/\.\[(\d+)\]/g, "[$1]");
|
|
337
|
+
invariant2(isJsonPath(jsonPath), `Invalid JsonPath: ${jsonPath}`, {
|
|
338
|
+
F: __dxlog_file2,
|
|
339
|
+
L: 67,
|
|
340
|
+
S: void 0,
|
|
341
|
+
A: [
|
|
342
|
+
"isJsonPath(jsonPath)",
|
|
343
|
+
"`Invalid JsonPath: ${jsonPath}`"
|
|
344
|
+
]
|
|
345
|
+
});
|
|
346
|
+
return jsonPath;
|
|
347
|
+
};
|
|
348
|
+
var splitJsonPath = (path) => {
|
|
349
|
+
if (!isJsonPath(path)) {
|
|
350
|
+
return [];
|
|
351
|
+
}
|
|
352
|
+
return path.match(/[a-zA-Z_$][\w$]*|\[\d+\]/g)?.map((part) => part.startsWith("[") ? part.replace(/[[\]]/g, "") : part) ?? [];
|
|
353
|
+
};
|
|
354
|
+
|
|
308
355
|
// packages/common/effect/src/url.ts
|
|
309
356
|
import { AST as AST2 } from "@effect/schema";
|
|
310
357
|
import { Option as Option2, pipe as pipe2 } from "effect";
|
|
@@ -365,23 +412,27 @@ export {
|
|
|
365
412
|
JsonPath,
|
|
366
413
|
JsonProp,
|
|
367
414
|
ParamKeyAnnotation,
|
|
368
|
-
|
|
415
|
+
S3 as S,
|
|
369
416
|
SimpleType,
|
|
370
417
|
UrlParser,
|
|
371
418
|
VisitResult,
|
|
419
|
+
createJsonPath,
|
|
372
420
|
findAnnotation,
|
|
373
421
|
findNode,
|
|
374
422
|
findProperty,
|
|
423
|
+
fromEffectValidationPath,
|
|
375
424
|
getAnnotation,
|
|
376
425
|
getDiscriminatedType,
|
|
377
426
|
getDiscriminatingProps,
|
|
378
427
|
getParamKeyAnnotation,
|
|
379
428
|
getSimpleType,
|
|
380
429
|
isDiscriminatedUnion,
|
|
430
|
+
isJsonPath,
|
|
381
431
|
isLiteralUnion,
|
|
382
432
|
isOption,
|
|
383
433
|
isSimpleType,
|
|
384
434
|
mapAst,
|
|
435
|
+
splitJsonPath,
|
|
385
436
|
visit
|
|
386
437
|
};
|
|
387
438
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 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;;
|
|
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", "
|
|
3
|
+
"sources": ["../../../src/index.ts", "../../../src/ast.ts", "../../../src/jsonPath.ts", "../../../src/url.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2020 DXOS.org\n//\n\nimport { AST, JSONSchema, Schema as S } from '@effect/schema';\nimport type * as Types from 'effect/Types';\n\n// TODO(dmaretskyi): Remove re-exports.\nexport { AST, JSONSchema, S, Types };\n\nexport * from './ast';\nexport * from './jsonPath';\nexport * from './url';\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { AST, Schema as S } from '@effect/schema';\nimport { Option, pipe } from 'effect';\n\nimport { invariant } from '@dxos/invariant';\nimport { nonNullable } 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(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 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,OAAAA,MAAKC,YAAYC,UAAUC,UAAS;;;ACA7C,SAASC,KAAKC,UAAUC,SAAS;AACjC,SAASC,QAAQC,YAAY;AAE7B,SAASC,iBAAiB;AAC1B,SAASC,mBAAmB;;AAgBrB,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,IAAIc,gBAAgBN,IAAAA,GAAO;AAC7B,WAAO;EACT;AACA,MAAIR,IAAIe,iBAAiBP,IAAAA,GAAO;A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a,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", "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", "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":40586,"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/effect/src/jsonPath.ts":{"bytes":8452,"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect/Option","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true}],"format":"esm"},"packages/common/effect/src/url.ts":{"bytes":7711,"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/common/effect/src/index.ts":{"bytes":1238,"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"packages/common/effect/src/ast.ts","kind":"import-statement","original":"./ast"},{"path":"packages/common/effect/src/jsonPath.ts","kind":"import-statement","original":"./jsonPath"},{"path":"packages/common/effect/src/url.ts","kind":"import-statement","original":"./url"}],"format":"esm"}},"outputs":{"packages/common/effect/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":29097},"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/Option","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["AST","JSONSchema","JsonPath","JsonProp","ParamKeyAnnotation","S","SimpleType","UrlParser","VisitResult","createJsonPath","findAnnotation","findNode","findProperty","fromEffectValidationPath","getAnnotation","getDiscriminatedType","getDiscriminatingProps","getParamKeyAnnotation","getSimpleType","isDiscriminatedUnion","isJsonPath","isLiteralUnion","isOption","isSimpleType","mapAst","splitJsonPath","visit"],"entryPoint":"packages/common/effect/src/index.ts","inputs":{"packages/common/effect/src/index.ts":{"bytesInOutput":72},"packages/common/effect/src/ast.ts":{"bytesInOutput":8509},"packages/common/effect/src/jsonPath.ts":{"bytesInOutput":1558},"packages/common/effect/src/url.ts":{"bytesInOutput":1624}},"bytes":12450}}}
|
package/dist/lib/node/index.cjs
CHANGED
|
@@ -27,19 +27,23 @@ __export(node_exports, {
|
|
|
27
27
|
SimpleType: () => SimpleType,
|
|
28
28
|
UrlParser: () => UrlParser,
|
|
29
29
|
VisitResult: () => VisitResult,
|
|
30
|
+
createJsonPath: () => createJsonPath,
|
|
30
31
|
findAnnotation: () => findAnnotation,
|
|
31
32
|
findNode: () => findNode,
|
|
32
33
|
findProperty: () => findProperty,
|
|
34
|
+
fromEffectValidationPath: () => fromEffectValidationPath,
|
|
33
35
|
getAnnotation: () => getAnnotation,
|
|
34
36
|
getDiscriminatedType: () => getDiscriminatedType,
|
|
35
37
|
getDiscriminatingProps: () => getDiscriminatingProps,
|
|
36
38
|
getParamKeyAnnotation: () => getParamKeyAnnotation,
|
|
37
39
|
getSimpleType: () => getSimpleType,
|
|
38
40
|
isDiscriminatedUnion: () => isDiscriminatedUnion,
|
|
41
|
+
isJsonPath: () => isJsonPath,
|
|
39
42
|
isLiteralUnion: () => isLiteralUnion,
|
|
40
43
|
isOption: () => isOption,
|
|
41
44
|
isSimpleType: () => isSimpleType,
|
|
42
45
|
mapAst: () => mapAst,
|
|
46
|
+
splitJsonPath: () => splitJsonPath,
|
|
43
47
|
visit: () => visit
|
|
44
48
|
});
|
|
45
49
|
module.exports = __toCommonJS(node_exports);
|
|
@@ -49,11 +53,14 @@ var import_effect = require("effect");
|
|
|
49
53
|
var import_invariant = require("@dxos/invariant");
|
|
50
54
|
var import_util = require("@dxos/util");
|
|
51
55
|
var import_schema3 = require("@effect/schema");
|
|
56
|
+
var import_Option = require("effect/Option");
|
|
57
|
+
var import_invariant2 = require("@dxos/invariant");
|
|
58
|
+
var import_schema4 = require("@effect/schema");
|
|
52
59
|
var import_effect2 = require("effect");
|
|
53
60
|
var import_util2 = require("@dxos/util");
|
|
54
61
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/common/effect/src/ast.ts";
|
|
55
62
|
var getSimpleType = (node) => {
|
|
56
|
-
if (import_schema2.AST.isObjectKeyword(node) || import_schema2.AST.isTypeLiteral(node) || isDiscriminatedUnion(node)) {
|
|
63
|
+
if (import_schema2.AST.isObjectKeyword(node) || import_schema2.AST.isTypeLiteral(node) || isDiscriminatedUnion(node) || import_schema2.AST.isDeclaration(node)) {
|
|
57
64
|
return "object";
|
|
58
65
|
}
|
|
59
66
|
if (import_schema2.AST.isStringKeyword(node)) {
|
|
@@ -95,10 +102,6 @@ var SimpleType;
|
|
|
95
102
|
}
|
|
96
103
|
};
|
|
97
104
|
})(SimpleType || (SimpleType = {}));
|
|
98
|
-
var PATH_REGEX = /[a-zA-Z_$][\w$]*(?:\.[a-zA-Z_$][\w$]*)*/;
|
|
99
|
-
var PROP_REGEX = /\w+/;
|
|
100
|
-
var JsonPath = import_schema2.Schema.NonEmptyString.pipe(import_schema2.Schema.pattern(PATH_REGEX));
|
|
101
|
-
var JsonProp = import_schema2.Schema.NonEmptyString.pipe(import_schema2.Schema.pattern(PROP_REGEX));
|
|
102
105
|
var VisitResult;
|
|
103
106
|
(function(VisitResult2) {
|
|
104
107
|
VisitResult2[VisitResult2["CONTINUE"] = 0] = "CONTINUE";
|
|
@@ -194,7 +197,7 @@ var findProperty = (schema, path) => {
|
|
|
194
197
|
const typeNode = findNode(node, import_schema2.AST.isTypeLiteral);
|
|
195
198
|
(0, import_invariant.invariant)(typeNode, void 0, {
|
|
196
199
|
F: __dxlog_file,
|
|
197
|
-
L:
|
|
200
|
+
L: 239,
|
|
198
201
|
S: void 0,
|
|
199
202
|
A: [
|
|
200
203
|
"typeNode",
|
|
@@ -254,7 +257,7 @@ var isDiscriminatedUnion = (node) => {
|
|
|
254
257
|
var getDiscriminatingProps = (node) => {
|
|
255
258
|
(0, import_invariant.invariant)(import_schema2.AST.isUnion(node), void 0, {
|
|
256
259
|
F: __dxlog_file,
|
|
257
|
-
L:
|
|
260
|
+
L: 336,
|
|
258
261
|
S: void 0,
|
|
259
262
|
A: [
|
|
260
263
|
"AST.isUnion(node)",
|
|
@@ -272,7 +275,7 @@ var getDiscriminatingProps = (node) => {
|
|
|
272
275
|
var getDiscriminatedType = (node, value = {}) => {
|
|
273
276
|
(0, import_invariant.invariant)(import_schema2.AST.isUnion(node), void 0, {
|
|
274
277
|
F: __dxlog_file,
|
|
275
|
-
L:
|
|
278
|
+
L: 357,
|
|
276
279
|
S: void 0,
|
|
277
280
|
A: [
|
|
278
281
|
"AST.isUnion(node)",
|
|
@@ -281,7 +284,7 @@ var getDiscriminatedType = (node, value = {}) => {
|
|
|
281
284
|
});
|
|
282
285
|
(0, import_invariant.invariant)(value, void 0, {
|
|
283
286
|
F: __dxlog_file,
|
|
284
|
-
L:
|
|
287
|
+
L: 358,
|
|
285
288
|
S: void 0,
|
|
286
289
|
A: [
|
|
287
290
|
"value",
|
|
@@ -296,7 +299,7 @@ var getDiscriminatedType = (node, value = {}) => {
|
|
|
296
299
|
const match = import_schema2.AST.getPropertySignatures(type).filter((prop) => props?.includes(prop.name.toString())).every((prop) => {
|
|
297
300
|
(0, import_invariant.invariant)(import_schema2.AST.isLiteral(prop.type), void 0, {
|
|
298
301
|
F: __dxlog_file,
|
|
299
|
-
L:
|
|
302
|
+
L: 369,
|
|
300
303
|
S: void 0,
|
|
301
304
|
A: [
|
|
302
305
|
"AST.isLiteral(prop.type)",
|
|
@@ -314,7 +317,7 @@ var getDiscriminatedType = (node, value = {}) => {
|
|
|
314
317
|
const literal = import_schema2.AST.getPropertySignatures(type).find((p) => p.name.toString() === prop);
|
|
315
318
|
(0, import_invariant.invariant)(import_schema2.AST.isLiteral(literal.type), void 0, {
|
|
316
319
|
F: __dxlog_file,
|
|
317
|
-
L:
|
|
320
|
+
L: 387,
|
|
318
321
|
S: void 0,
|
|
319
322
|
A: [
|
|
320
323
|
"AST.isLiteral(literal.type)",
|
|
@@ -334,21 +337,67 @@ var getDiscriminatedType = (node, value = {}) => {
|
|
|
334
337
|
var mapAst = (ast, f) => {
|
|
335
338
|
switch (ast._tag) {
|
|
336
339
|
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);
|
|
340
|
+
return new import_schema2.AST.TypeLiteral(ast.propertySignatures.map((prop) => new import_schema2.AST.PropertySignature(prop.name, f(prop.type, prop.name), prop.isOptional, prop.isReadonly, prop.annotations)), ast.indexSignatures);
|
|
338
341
|
case "Union":
|
|
339
342
|
return import_schema2.AST.Union.make(ast.types.map(f), ast.annotations);
|
|
340
343
|
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);
|
|
344
|
+
return new import_schema2.AST.TupleType(ast.elements.map((t, index) => new import_schema2.AST.OptionalType(f(t.type, index), t.isOptional, t.annotations)), ast.rest.map((t) => new import_schema2.AST.Type(f(t.type, void 0), t.annotations)), ast.isReadonly, ast.annotations);
|
|
342
345
|
case "Suspend": {
|
|
343
|
-
const newAst = f(ast.f());
|
|
346
|
+
const newAst = f(ast.f(), void 0);
|
|
344
347
|
return new import_schema2.AST.Suspend(() => newAst, ast.annotations);
|
|
345
348
|
}
|
|
346
349
|
default:
|
|
347
350
|
return ast;
|
|
348
351
|
}
|
|
349
352
|
};
|
|
353
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/common/effect/src/jsonPath.ts";
|
|
354
|
+
var PATH_REGEX = /^($|[a-zA-Z_$][\w$]*(?:\.[a-zA-Z_$][\w$]*|\[\d+\](?:\.)?)*$)/;
|
|
355
|
+
var PROP_REGEX = /\w+/;
|
|
356
|
+
var JsonPath = import_schema3.Schema.String.pipe(import_schema3.Schema.pattern(PATH_REGEX));
|
|
357
|
+
var JsonProp = import_schema3.Schema.NonEmptyString.pipe(import_schema3.Schema.pattern(PROP_REGEX));
|
|
358
|
+
var isJsonPath = (value) => {
|
|
359
|
+
return (0, import_Option.isSome)(import_schema3.Schema.validateOption(JsonPath)(value));
|
|
360
|
+
};
|
|
361
|
+
var createJsonPath = (path) => {
|
|
362
|
+
const candidatePath = path.map((p, i) => {
|
|
363
|
+
if (typeof p === "number") {
|
|
364
|
+
return `[${p}]`;
|
|
365
|
+
} else {
|
|
366
|
+
return i === 0 ? p : `.${p}`;
|
|
367
|
+
}
|
|
368
|
+
}).join("");
|
|
369
|
+
(0, import_invariant2.invariant)(isJsonPath(candidatePath), `Invalid JsonPath: ${candidatePath}`, {
|
|
370
|
+
F: __dxlog_file2,
|
|
371
|
+
L: 56,
|
|
372
|
+
S: void 0,
|
|
373
|
+
A: [
|
|
374
|
+
"isJsonPath(candidatePath)",
|
|
375
|
+
"`Invalid JsonPath: ${candidatePath}`"
|
|
376
|
+
]
|
|
377
|
+
});
|
|
378
|
+
return candidatePath;
|
|
379
|
+
};
|
|
380
|
+
var fromEffectValidationPath = (effectPath) => {
|
|
381
|
+
const jsonPath = effectPath.replace(/\.\[(\d+)\]/g, "[$1]");
|
|
382
|
+
(0, import_invariant2.invariant)(isJsonPath(jsonPath), `Invalid JsonPath: ${jsonPath}`, {
|
|
383
|
+
F: __dxlog_file2,
|
|
384
|
+
L: 67,
|
|
385
|
+
S: void 0,
|
|
386
|
+
A: [
|
|
387
|
+
"isJsonPath(jsonPath)",
|
|
388
|
+
"`Invalid JsonPath: ${jsonPath}`"
|
|
389
|
+
]
|
|
390
|
+
});
|
|
391
|
+
return jsonPath;
|
|
392
|
+
};
|
|
393
|
+
var splitJsonPath = (path) => {
|
|
394
|
+
if (!isJsonPath(path)) {
|
|
395
|
+
return [];
|
|
396
|
+
}
|
|
397
|
+
return path.match(/[a-zA-Z_$][\w$]*|\[\d+\]/g)?.map((part) => part.startsWith("[") ? part.replace(/[[\]]/g, "") : part) ?? [];
|
|
398
|
+
};
|
|
350
399
|
var ParamKeyAnnotationId = Symbol.for("@dxos/schema/annotation/ParamKey");
|
|
351
|
-
var getParamKeyAnnotation =
|
|
400
|
+
var getParamKeyAnnotation = import_schema4.AST.getAnnotation(ParamKeyAnnotationId);
|
|
352
401
|
var ParamKeyAnnotation = (value) => (self) => self.annotations({
|
|
353
402
|
[ParamKeyAnnotationId]: value
|
|
354
403
|
});
|
|
@@ -367,9 +416,9 @@ var UrlParser = class {
|
|
|
367
416
|
value = url.searchParams.get(key);
|
|
368
417
|
}
|
|
369
418
|
if (value != null) {
|
|
370
|
-
if (
|
|
419
|
+
if (import_schema4.AST.isNumberKeyword(type.ast)) {
|
|
371
420
|
params[key] = parseInt(value);
|
|
372
|
-
} else if (
|
|
421
|
+
} else if (import_schema4.AST.isBooleanKeyword(type.ast)) {
|
|
373
422
|
params[key] = value === "true" || value === "1";
|
|
374
423
|
} else {
|
|
375
424
|
params[key] = value;
|
|
@@ -408,19 +457,23 @@ var UrlParser = class {
|
|
|
408
457
|
SimpleType,
|
|
409
458
|
UrlParser,
|
|
410
459
|
VisitResult,
|
|
460
|
+
createJsonPath,
|
|
411
461
|
findAnnotation,
|
|
412
462
|
findNode,
|
|
413
463
|
findProperty,
|
|
464
|
+
fromEffectValidationPath,
|
|
414
465
|
getAnnotation,
|
|
415
466
|
getDiscriminatedType,
|
|
416
467
|
getDiscriminatingProps,
|
|
417
468
|
getParamKeyAnnotation,
|
|
418
469
|
getSimpleType,
|
|
419
470
|
isDiscriminatedUnion,
|
|
471
|
+
isJsonPath,
|
|
420
472
|
isLiteralUnion,
|
|
421
473
|
isOption,
|
|
422
474
|
isSimpleType,
|
|
423
475
|
mapAst,
|
|
476
|
+
splitJsonPath,
|
|
424
477
|
visit
|
|
425
478
|
});
|
|
426
479
|
//# sourceMappingURL=index.cjs.map
|