@dxos/effect 0.6.12-staging.e11e696 → 0.6.13-main.09887cd
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 +42 -4
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +39 -5
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +42 -4
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/decamelize.d.ts +2 -0
- package/dist/types/src/decamelize.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +3 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/url.d.ts +3 -1
- package/dist/types/src/url.d.ts.map +1 -1
- package/dist/types/src/util.d.ts +3 -0
- package/dist/types/src/util.d.ts.map +1 -0
- package/package.json +5 -6
- package/src/decamelize.ts +36 -0
- package/src/index.ts +3 -1
- package/src/url.ts +3 -2
- package/src/util.ts +11 -0
|
@@ -8,12 +8,43 @@ import {
|
|
|
8
8
|
} from "@dxos/node-std/inject-globals";
|
|
9
9
|
|
|
10
10
|
// packages/common/effect/src/index.ts
|
|
11
|
-
import { AST as
|
|
11
|
+
import { AST as AST3, JSONSchema, Schema as S } from "@effect/schema";
|
|
12
12
|
|
|
13
13
|
// packages/common/effect/src/url.ts
|
|
14
14
|
import { AST } from "@effect/schema";
|
|
15
15
|
import { Option, pipe } from "effect";
|
|
16
|
-
|
|
16
|
+
|
|
17
|
+
// packages/common/effect/src/decamelize.ts
|
|
18
|
+
var LOW_DASH = "_".codePointAt(0);
|
|
19
|
+
var SMALL_A = "a".codePointAt(0);
|
|
20
|
+
var CAPITAL_A = "A".codePointAt(0);
|
|
21
|
+
var SMALL_Z = "z".codePointAt(0);
|
|
22
|
+
var CAPITAL_Z = "Z".codePointAt(0);
|
|
23
|
+
var isLower = (char) => char >= SMALL_A && char <= SMALL_Z;
|
|
24
|
+
var isUpper = (char) => char >= CAPITAL_A && char <= CAPITAL_Z;
|
|
25
|
+
var toLower = (char) => char + 32;
|
|
26
|
+
var decamelize = (str) => {
|
|
27
|
+
const firstChar = str.charCodeAt(0);
|
|
28
|
+
if (!isLower(firstChar)) {
|
|
29
|
+
return str;
|
|
30
|
+
}
|
|
31
|
+
const length = str.length;
|
|
32
|
+
let changed = false;
|
|
33
|
+
const out = [];
|
|
34
|
+
for (let i = 0; i < length; ++i) {
|
|
35
|
+
const c = str.charCodeAt(i);
|
|
36
|
+
if (isUpper(c)) {
|
|
37
|
+
out.push(LOW_DASH);
|
|
38
|
+
out.push(toLower(c));
|
|
39
|
+
changed = true;
|
|
40
|
+
} else {
|
|
41
|
+
out.push(c);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return changed ? String.fromCharCode.apply(void 0, out) : str;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// packages/common/effect/src/url.ts
|
|
17
48
|
var ParamKeyAnnotationId = Symbol.for("@dxos/schema/annotation/ParamKey");
|
|
18
49
|
var getParamKeyAnnotation = AST.getAnnotation(ParamKeyAnnotationId);
|
|
19
50
|
var ParamKeyAnnotation = (value) => (self) => self.annotations({
|
|
@@ -64,11 +95,18 @@ var UrlParser = class {
|
|
|
64
95
|
return url;
|
|
65
96
|
}
|
|
66
97
|
};
|
|
98
|
+
|
|
99
|
+
// packages/common/effect/src/util.ts
|
|
100
|
+
import { AST as AST2 } from "@effect/schema";
|
|
101
|
+
import { Option as Option2, pipe as pipe2 } from "effect";
|
|
102
|
+
var getAnnotation = (annotationId) => (annotated) => pipe2(AST2.getAnnotation(annotationId)(annotated), Option2.getOrUndefined);
|
|
67
103
|
export {
|
|
68
|
-
|
|
104
|
+
AST3 as AST,
|
|
69
105
|
JSONSchema,
|
|
70
106
|
ParamKeyAnnotation,
|
|
71
107
|
S,
|
|
72
|
-
UrlParser
|
|
108
|
+
UrlParser,
|
|
109
|
+
getAnnotation,
|
|
110
|
+
getParamKeyAnnotation
|
|
73
111
|
};
|
|
74
112
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/index.ts", "../../../src/url.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2020 DXOS.org\n//\n\nimport { AST, JSONSchema, Schema as S } from '@effect/schema';\n\nexport { AST, JSONSchema, S };\n\nexport * from './url';\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { AST, type Schema as S } from '@effect/schema';\nimport { Option, pipe } from 'effect';\nimport { decamelize } from '
|
|
5
|
-
"mappings": ";;;;;;;;;;AAIA,SAASA,OAAAA,MAAKC,YAAYC,UAAUC,SAAS;;;ACA7C,SAASC,WAA6B;AACtC,SAASC,QAAQC,YAAY
|
|
6
|
-
"names": ["AST", "JSONSchema", "Schema", "S", "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"]
|
|
3
|
+
"sources": ["../../../src/index.ts", "../../../src/url.ts", "../../../src/decamelize.ts", "../../../src/util.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\nexport { AST, JSONSchema, S, Types };\n\nexport * from './url';\nexport * from './util';\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 './decamelize';\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", "//\n// Copyright 2024 DXOS.org\n//\n\nconst LOW_DASH = '_'.codePointAt(0)!;\nconst SMALL_A = 'a'.codePointAt(0)!;\nconst CAPITAL_A = 'A'.codePointAt(0)!;\nconst SMALL_Z = 'z'.codePointAt(0)!;\nconst CAPITAL_Z = 'Z'.codePointAt(0)!;\n\nconst isLower = (char: number) => char >= SMALL_A && char <= SMALL_Z;\n\nconst isUpper = (char: number) => char >= CAPITAL_A && char <= CAPITAL_Z;\n\nconst toLower = (char: number) => char + 0x20;\n\nexport const decamelize = (str: string) => {\n const firstChar = str.charCodeAt(0);\n if (!isLower(firstChar)) {\n return str;\n }\n const length = str.length;\n let changed = false;\n const out: number[] = [];\n for (let i = 0; i < length; ++i) {\n const c = str.charCodeAt(i);\n if (isUpper(c)) {\n out.push(LOW_DASH);\n out.push(toLower(c));\n changed = true;\n } else {\n out.push(c);\n }\n }\n return changed ? String.fromCharCode.apply(undefined, out) : str;\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { AST } from '@effect/schema';\nimport { Option, pipe } from 'effect';\n\nexport const getAnnotation =\n <T>(annotationId: symbol) =>\n (annotated: AST.Annotated): T | undefined =>\n pipe(AST.getAnnotation<T>(annotationId)(annotated), Option.getOrUndefined);\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;AAIA,SAASA,OAAAA,MAAKC,YAAYC,UAAUC,SAAS;;;ACA7C,SAASC,WAA6B;AACtC,SAASC,QAAQC,YAAY;;;ACD7B,IAAMC,WAAW,IAAIC,YAAY,CAAA;AACjC,IAAMC,UAAU,IAAID,YAAY,CAAA;AAChC,IAAME,YAAY,IAAIF,YAAY,CAAA;AAClC,IAAMG,UAAU,IAAIH,YAAY,CAAA;AAChC,IAAMI,YAAY,IAAIJ,YAAY,CAAA;AAElC,IAAMK,UAAU,CAACC,SAAiBA,QAAQL,WAAWK,QAAQH;AAE7D,IAAMI,UAAU,CAACD,SAAiBA,QAAQJ,aAAaI,QAAQF;AAE/D,IAAMI,UAAU,CAACF,SAAiBA,OAAO;AAElC,IAAMG,aAAa,CAACC,QAAAA;AACzB,QAAMC,YAAYD,IAAIE,WAAW,CAAA;AACjC,MAAI,CAACP,QAAQM,SAAAA,GAAY;AACvB,WAAOD;EACT;AACA,QAAMG,SAASH,IAAIG;AACnB,MAAIC,UAAU;AACd,QAAMC,MAAgB,C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A;EACN;;;;EAKAU,OAAOjB,MAAcO,QAAgB;AACnC,UAAMN,MAAM,IAAIC,IAAIF,IAAAA;AACpBG,WAAOC,QAAQG,MAAAA,EAAQW,QAAQ,CAAC,CAACV,KAAKf,KAAAA,MAAM;AAC1C,UAAIA,UAAU0B,QAAW;AACvB,cAAMC,QAAQ,KAAKtB,QAAQO,OAAOG,GAAAA;AAClC,YAAIY,OAAO;AACT,gBAAM,EAAEZ,KAAKa,cAAa,IAAKC,KAC7BjC,sBAAsB+B,MAAMN,GAAG,GAC/BS,OAAOC,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;;;AExEA,SAAS0B,OAAAA,YAAW;AACpB,SAASC,UAAAA,SAAQC,QAAAA,aAAY;AAEtB,IAAMC,gBACX,CAAIC,iBACJ,CAACC,cACCC,MAAKC,KAAIJ,cAAiBC,YAAAA,EAAcC,SAAAA,GAAYG,QAAOC,cAAc;",
|
|
6
|
+
"names": ["AST", "JSONSchema", "Schema", "S", "AST", "Option", "pipe", "LOW_DASH", "codePointAt", "SMALL_A", "CAPITAL_A", "SMALL_Z", "CAPITAL_Z", "isLower", "char", "isUpper", "toLower", "decamelize", "str", "firstChar", "charCodeAt", "length", "changed", "out", "i", "c", "push", "String", "fromCharCode", "apply", "undefined", "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", "AST", "Option", "pipe", "getAnnotation", "annotationId", "annotated", "pipe", "AST", "Option", "getOrUndefined"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"inject-globals:@inject-globals":{"bytes":324,"imports":[{"path":"@dxos/node-std/inject-globals","kind":"import-statement","external":true}],"format":"esm"},"packages/common/effect/src/url.ts":{"bytes":
|
|
1
|
+
{"inputs":{"inject-globals:@inject-globals":{"bytes":324,"imports":[{"path":"@dxos/node-std/inject-globals","kind":"import-statement","external":true}],"format":"esm"},"packages/common/effect/src/decamelize.ts":{"bytes":3867,"imports":[{"path":"@inject-globals","kind":"import-statement","external":true}],"format":"esm"},"packages/common/effect/src/url.ts":{"bytes":7713,"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"packages/common/effect/src/decamelize.ts","kind":"import-statement","original":"./decamelize"},{"path":"@inject-globals","kind":"import-statement","external":true}],"format":"esm"},"packages/common/effect/src/util.ts":{"bytes":1305,"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@inject-globals","kind":"import-statement","external":true}],"format":"esm"},"packages/common/effect/src/index.ts":{"bytes":1039,"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"packages/common/effect/src/url.ts","kind":"import-statement","original":"./url"},{"path":"packages/common/effect/src/util.ts","kind":"import-statement","original":"./util"},{"path":"@inject-globals","kind":"import-statement","external":true}],"format":"esm"}},"outputs":{"packages/common/effect/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":7004},"packages/common/effect/dist/lib/browser/index.mjs":{"imports":[{"path":"@dxos/node-std/inject-globals","kind":"import-statement","external":true},{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true}],"exports":["AST","JSONSchema","ParamKeyAnnotation","S","UrlParser","getAnnotation","getParamKeyAnnotation"],"entryPoint":"packages/common/effect/src/index.ts","inputs":{"inject-globals:@inject-globals":{"bytesInOutput":79},"packages/common/effect/src/index.ts":{"bytesInOutput":71},"packages/common/effect/src/url.ts":{"bytesInOutput":1550},"packages/common/effect/src/decamelize.ts":{"bytesInOutput":798},"packages/common/effect/src/util.ts":{"bytesInOutput":234}},"bytes":3157}}}
|
package/dist/lib/node/index.cjs
CHANGED
|
@@ -22,13 +22,44 @@ __export(node_exports, {
|
|
|
22
22
|
JSONSchema: () => import_schema.JSONSchema,
|
|
23
23
|
ParamKeyAnnotation: () => ParamKeyAnnotation,
|
|
24
24
|
S: () => import_schema.Schema,
|
|
25
|
-
UrlParser: () => UrlParser
|
|
25
|
+
UrlParser: () => UrlParser,
|
|
26
|
+
getAnnotation: () => getAnnotation,
|
|
27
|
+
getParamKeyAnnotation: () => getParamKeyAnnotation
|
|
26
28
|
});
|
|
27
29
|
module.exports = __toCommonJS(node_exports);
|
|
28
30
|
var import_schema = require("@effect/schema");
|
|
29
31
|
var import_schema2 = require("@effect/schema");
|
|
30
32
|
var import_effect = require("effect");
|
|
31
|
-
var
|
|
33
|
+
var import_schema3 = require("@effect/schema");
|
|
34
|
+
var import_effect2 = require("effect");
|
|
35
|
+
var LOW_DASH = "_".codePointAt(0);
|
|
36
|
+
var SMALL_A = "a".codePointAt(0);
|
|
37
|
+
var CAPITAL_A = "A".codePointAt(0);
|
|
38
|
+
var SMALL_Z = "z".codePointAt(0);
|
|
39
|
+
var CAPITAL_Z = "Z".codePointAt(0);
|
|
40
|
+
var isLower = (char) => char >= SMALL_A && char <= SMALL_Z;
|
|
41
|
+
var isUpper = (char) => char >= CAPITAL_A && char <= CAPITAL_Z;
|
|
42
|
+
var toLower = (char) => char + 32;
|
|
43
|
+
var decamelize = (str) => {
|
|
44
|
+
const firstChar = str.charCodeAt(0);
|
|
45
|
+
if (!isLower(firstChar)) {
|
|
46
|
+
return str;
|
|
47
|
+
}
|
|
48
|
+
const length = str.length;
|
|
49
|
+
let changed = false;
|
|
50
|
+
const out = [];
|
|
51
|
+
for (let i = 0; i < length; ++i) {
|
|
52
|
+
const c = str.charCodeAt(i);
|
|
53
|
+
if (isUpper(c)) {
|
|
54
|
+
out.push(LOW_DASH);
|
|
55
|
+
out.push(toLower(c));
|
|
56
|
+
changed = true;
|
|
57
|
+
} else {
|
|
58
|
+
out.push(c);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return changed ? String.fromCharCode.apply(void 0, out) : str;
|
|
62
|
+
};
|
|
32
63
|
var ParamKeyAnnotationId = Symbol.for("@dxos/schema/annotation/ParamKey");
|
|
33
64
|
var getParamKeyAnnotation = import_schema2.AST.getAnnotation(ParamKeyAnnotationId);
|
|
34
65
|
var ParamKeyAnnotation = (value) => (self) => self.annotations({
|
|
@@ -44,7 +75,7 @@ var UrlParser = class {
|
|
|
44
75
|
parse(_url) {
|
|
45
76
|
const url = new URL(_url);
|
|
46
77
|
return Object.entries(this._schema.fields).reduce((params, [key, type]) => {
|
|
47
|
-
let value = url.searchParams.get(
|
|
78
|
+
let value = url.searchParams.get(decamelize(key));
|
|
48
79
|
if (value == null) {
|
|
49
80
|
value = url.searchParams.get(key);
|
|
50
81
|
}
|
|
@@ -70,7 +101,7 @@ var UrlParser = class {
|
|
|
70
101
|
const field = this._schema.fields[key];
|
|
71
102
|
if (field) {
|
|
72
103
|
const { key: serializedKey } = (0, import_effect.pipe)(getParamKeyAnnotation(field.ast), import_effect.Option.getOrElse(() => ({
|
|
73
|
-
key:
|
|
104
|
+
key: decamelize(key)
|
|
74
105
|
})));
|
|
75
106
|
url.searchParams.set(serializedKey, String(value));
|
|
76
107
|
}
|
|
@@ -79,12 +110,15 @@ var UrlParser = class {
|
|
|
79
110
|
return url;
|
|
80
111
|
}
|
|
81
112
|
};
|
|
113
|
+
var getAnnotation = (annotationId) => (annotated) => (0, import_effect2.pipe)(import_schema3.AST.getAnnotation(annotationId)(annotated), import_effect2.Option.getOrUndefined);
|
|
82
114
|
// Annotate the CommonJS export names for ESM import in node:
|
|
83
115
|
0 && (module.exports = {
|
|
84
116
|
AST,
|
|
85
117
|
JSONSchema,
|
|
86
118
|
ParamKeyAnnotation,
|
|
87
119
|
S,
|
|
88
|
-
UrlParser
|
|
120
|
+
UrlParser,
|
|
121
|
+
getAnnotation,
|
|
122
|
+
getParamKeyAnnotation
|
|
89
123
|
});
|
|
90
124
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/index.ts", "../../../src/url.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2020 DXOS.org\n//\n\nimport { AST, JSONSchema, Schema as S } from '@effect/schema';\n\nexport { AST, JSONSchema, S };\n\nexport * from './url';\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { AST, type Schema as S } from '@effect/schema';\nimport { Option, pipe } from 'effect';\nimport { decamelize } from '
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["import_schema", "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", "
|
|
3
|
+
"sources": ["../../../src/index.ts", "../../../src/url.ts", "../../../src/decamelize.ts", "../../../src/util.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\nexport { AST, JSONSchema, S, Types };\n\nexport * from './url';\nexport * from './util';\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 './decamelize';\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", "//\n// Copyright 2024 DXOS.org\n//\n\nconst LOW_DASH = '_'.codePointAt(0)!;\nconst SMALL_A = 'a'.codePointAt(0)!;\nconst CAPITAL_A = 'A'.codePointAt(0)!;\nconst SMALL_Z = 'z'.codePointAt(0)!;\nconst CAPITAL_Z = 'Z'.codePointAt(0)!;\n\nconst isLower = (char: number) => char >= SMALL_A && char <= SMALL_Z;\n\nconst isUpper = (char: number) => char >= CAPITAL_A && char <= CAPITAL_Z;\n\nconst toLower = (char: number) => char + 0x20;\n\nexport const decamelize = (str: string) => {\n const firstChar = str.charCodeAt(0);\n if (!isLower(firstChar)) {\n return str;\n }\n const length = str.length;\n let changed = false;\n const out: number[] = [];\n for (let i = 0; i < length; ++i) {\n const c = str.charCodeAt(i);\n if (isUpper(c)) {\n out.push(LOW_DASH);\n out.push(toLower(c));\n changed = true;\n } else {\n out.push(c);\n }\n }\n return changed ? String.fromCharCode.apply(undefined, out) : str;\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { AST } from '@effect/schema';\nimport { Option, pipe } from 'effect';\n\nexport const getAnnotation =\n <T>(annotationId: symbol) =>\n (annotated: AST.Annotated): T | undefined =>\n pipe(AST.getAnnotation<T>(annotationId)(annotated), Option.getOrUndefined);\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,oBAA6C;ACA7C,IAAAA,iBAAsC;AACtC,oBAA6B;AED7B,IAAAA,iBAAoB;AACpB,IAAAC,iBAA6B;ADD7B,IAAMC,WAAW,IAAIC,YAAY,CAAA;AACjC,IAAMC,UAAU,IAAID,YAAY,CAAA;AAChC,IAAME,YAAY,IAAIF,YAAY,CAAA;AAClC,IAAMG,UAAU,IAAIH,YAAY,CAAA;AAChC,IAAMI,YAAY,IAAIJ,YAAY,CAAA;AAElC,IAAMK,UAAU,CAACC,SAAiBA,QAAQL,WAAWK,QAAQH;AAE7D,IAAMI,UAAU,CAACD,SAAiBA,QAAQJ,aAAaI,QAAQF;AAE/D,IAAMI,UAAU,CAACF,SAAiBA,OAAO;AAElC,IAAMG,aAAa,CAACC,QAAAA;AACzB,QAAMC,YAAYD,IAAIE,WAAW,CAAA;AACjC,MAAI,CAACP,QAAQM,SAAAA,GAAY;AACvB,WAAOD;EACT;AACA,QAAMG,SAASH,IAAIG;AACnB,MAAIC,UAAU;AACd,QAAMC,MAAgB,CAAA;AACtB,WAASC,IAAI,GAAGA,IAAIH,QAAQ,EAAEG,GAAG;AAC/B,UAAMC,IAAI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AAAA;AACpBG,WAAOC,QAAQG,MAAAA,EAAQU,QAAQ,CAAC,CAACT,KAAKf,KAAAA,MAAM;AAC1C,UAAIA,UAAUR,QAAW;AACvB,cAAMiC,QAAQ,KAAKpB,QAAQO,OAAOG,GAAAA;AAClC,YAAIU,OAAO;AACT,gBAAM,EAAEV,KAAKW,cAAa,QAAKC,oBAC7B/B,sBAAsB6B,MAAML,GAAG,GAC/BQ,qBAAOC,UAAU,OAAO;YACtBd,KAAKpC,WAAWoC,GAAAA;UAClB,EAAA,CAAA;AAGFP,cAAIS,aAAaa,IAAIJ,eAAerC,OAAOW,KAAAA,CAAAA;QAC7C;MACF;IACF,CAAA;AAEA,WAAOQ;EACT;AACF;AErEO,IAAMV,gBACX,CAAIiC,iBACJ,CAACC,kBACCL,eAAAA,MAAK9B,eAAAA,IAAIC,cAAiBiC,YAAAA,EAAcC,SAAAA,GAAYJ,eAAAA,OAAOK,cAAc;",
|
|
6
|
+
"names": ["import_schema", "import_effect", "LOW_DASH", "codePointAt", "SMALL_A", "CAPITAL_A", "SMALL_Z", "CAPITAL_Z", "isLower", "char", "isUpper", "toLower", "decamelize", "str", "firstChar", "charCodeAt", "length", "changed", "out", "i", "c", "push", "String", "fromCharCode", "apply", "undefined", "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", "isNumberKeyword", "ast", "parseInt", "isBooleanKeyword", "create", "forEach", "field", "serializedKey", "pipe", "Option", "getOrElse", "set", "annotationId", "annotated", "getOrUndefined"]
|
|
7
7
|
}
|
package/dist/lib/node/meta.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/common/effect/src/url.ts":{"bytes":
|
|
1
|
+
{"inputs":{"packages/common/effect/src/decamelize.ts":{"bytes":3867,"imports":[],"format":"esm"},"packages/common/effect/src/url.ts":{"bytes":7713,"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"packages/common/effect/src/decamelize.ts","kind":"import-statement","original":"./decamelize"}],"format":"esm"},"packages/common/effect/src/util.ts":{"bytes":1305,"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true}],"format":"esm"},"packages/common/effect/src/index.ts":{"bytes":1039,"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"packages/common/effect/src/url.ts","kind":"import-statement","original":"./url"},{"path":"packages/common/effect/src/util.ts","kind":"import-statement","original":"./util"}],"format":"esm"}},"outputs":{"packages/common/effect/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":6995},"packages/common/effect/dist/lib/node/index.cjs":{"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true}],"exports":["AST","JSONSchema","ParamKeyAnnotation","S","UrlParser","getAnnotation","getParamKeyAnnotation"],"entryPoint":"packages/common/effect/src/index.ts","inputs":{"packages/common/effect/src/index.ts":{"bytesInOutput":71},"packages/common/effect/src/url.ts":{"bytesInOutput":1550},"packages/common/effect/src/decamelize.ts":{"bytesInOutput":798},"packages/common/effect/src/util.ts":{"bytesInOutput":234}},"bytes":3009}}}
|
|
@@ -1,12 +1,43 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
2
|
|
|
3
3
|
// packages/common/effect/src/index.ts
|
|
4
|
-
import { AST as
|
|
4
|
+
import { AST as AST3, JSONSchema, Schema as S } from "@effect/schema";
|
|
5
5
|
|
|
6
6
|
// packages/common/effect/src/url.ts
|
|
7
7
|
import { AST } from "@effect/schema";
|
|
8
8
|
import { Option, pipe } from "effect";
|
|
9
|
-
|
|
9
|
+
|
|
10
|
+
// packages/common/effect/src/decamelize.ts
|
|
11
|
+
var LOW_DASH = "_".codePointAt(0);
|
|
12
|
+
var SMALL_A = "a".codePointAt(0);
|
|
13
|
+
var CAPITAL_A = "A".codePointAt(0);
|
|
14
|
+
var SMALL_Z = "z".codePointAt(0);
|
|
15
|
+
var CAPITAL_Z = "Z".codePointAt(0);
|
|
16
|
+
var isLower = (char) => char >= SMALL_A && char <= SMALL_Z;
|
|
17
|
+
var isUpper = (char) => char >= CAPITAL_A && char <= CAPITAL_Z;
|
|
18
|
+
var toLower = (char) => char + 32;
|
|
19
|
+
var decamelize = (str) => {
|
|
20
|
+
const firstChar = str.charCodeAt(0);
|
|
21
|
+
if (!isLower(firstChar)) {
|
|
22
|
+
return str;
|
|
23
|
+
}
|
|
24
|
+
const length = str.length;
|
|
25
|
+
let changed = false;
|
|
26
|
+
const out = [];
|
|
27
|
+
for (let i = 0; i < length; ++i) {
|
|
28
|
+
const c = str.charCodeAt(i);
|
|
29
|
+
if (isUpper(c)) {
|
|
30
|
+
out.push(LOW_DASH);
|
|
31
|
+
out.push(toLower(c));
|
|
32
|
+
changed = true;
|
|
33
|
+
} else {
|
|
34
|
+
out.push(c);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return changed ? String.fromCharCode.apply(void 0, out) : str;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// packages/common/effect/src/url.ts
|
|
10
41
|
var ParamKeyAnnotationId = Symbol.for("@dxos/schema/annotation/ParamKey");
|
|
11
42
|
var getParamKeyAnnotation = AST.getAnnotation(ParamKeyAnnotationId);
|
|
12
43
|
var ParamKeyAnnotation = (value) => (self) => self.annotations({
|
|
@@ -57,11 +88,18 @@ var UrlParser = class {
|
|
|
57
88
|
return url;
|
|
58
89
|
}
|
|
59
90
|
};
|
|
91
|
+
|
|
92
|
+
// packages/common/effect/src/util.ts
|
|
93
|
+
import { AST as AST2 } from "@effect/schema";
|
|
94
|
+
import { Option as Option2, pipe as pipe2 } from "effect";
|
|
95
|
+
var getAnnotation = (annotationId) => (annotated) => pipe2(AST2.getAnnotation(annotationId)(annotated), Option2.getOrUndefined);
|
|
60
96
|
export {
|
|
61
|
-
|
|
97
|
+
AST3 as AST,
|
|
62
98
|
JSONSchema,
|
|
63
99
|
ParamKeyAnnotation,
|
|
64
100
|
S,
|
|
65
|
-
UrlParser
|
|
101
|
+
UrlParser,
|
|
102
|
+
getAnnotation,
|
|
103
|
+
getParamKeyAnnotation
|
|
66
104
|
};
|
|
67
105
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/index.ts", "../../../src/url.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2020 DXOS.org\n//\n\nimport { AST, JSONSchema, Schema as S } from '@effect/schema';\n\nexport { AST, JSONSchema, S };\n\nexport * from './url';\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { AST, type Schema as S } from '@effect/schema';\nimport { Option, pipe } from 'effect';\nimport { decamelize } from '
|
|
5
|
-
"mappings": ";;;AAIA,SAASA,OAAAA,MAAKC,YAAYC,UAAUC,SAAS;;;ACA7C,SAASC,WAA6B;AACtC,SAASC,QAAQC,YAAY
|
|
6
|
-
"names": ["AST", "JSONSchema", "Schema", "S", "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"]
|
|
3
|
+
"sources": ["../../../src/index.ts", "../../../src/url.ts", "../../../src/decamelize.ts", "../../../src/util.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\nexport { AST, JSONSchema, S, Types };\n\nexport * from './url';\nexport * from './util';\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 './decamelize';\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", "//\n// Copyright 2024 DXOS.org\n//\n\nconst LOW_DASH = '_'.codePointAt(0)!;\nconst SMALL_A = 'a'.codePointAt(0)!;\nconst CAPITAL_A = 'A'.codePointAt(0)!;\nconst SMALL_Z = 'z'.codePointAt(0)!;\nconst CAPITAL_Z = 'Z'.codePointAt(0)!;\n\nconst isLower = (char: number) => char >= SMALL_A && char <= SMALL_Z;\n\nconst isUpper = (char: number) => char >= CAPITAL_A && char <= CAPITAL_Z;\n\nconst toLower = (char: number) => char + 0x20;\n\nexport const decamelize = (str: string) => {\n const firstChar = str.charCodeAt(0);\n if (!isLower(firstChar)) {\n return str;\n }\n const length = str.length;\n let changed = false;\n const out: number[] = [];\n for (let i = 0; i < length; ++i) {\n const c = str.charCodeAt(i);\n if (isUpper(c)) {\n out.push(LOW_DASH);\n out.push(toLower(c));\n changed = true;\n } else {\n out.push(c);\n }\n }\n return changed ? String.fromCharCode.apply(undefined, out) : str;\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { AST } from '@effect/schema';\nimport { Option, pipe } from 'effect';\n\nexport const getAnnotation =\n <T>(annotationId: symbol) =>\n (annotated: AST.Annotated): T | undefined =>\n pipe(AST.getAnnotation<T>(annotationId)(annotated), Option.getOrUndefined);\n"],
|
|
5
|
+
"mappings": ";;;AAIA,SAASA,OAAAA,MAAKC,YAAYC,UAAUC,SAAS;;;ACA7C,SAASC,WAA6B;AACtC,SAASC,QAAQC,YAAY;;;ACD7B,IAAMC,WAAW,IAAIC,YAAY,CAAA;AACjC,IAAMC,UAAU,IAAID,YAAY,CAAA;AAChC,IAAME,YAAY,IAAIF,YAAY,CAAA;AAClC,IAAMG,UAAU,IAAIH,YAAY,CAAA;AAChC,IAAMI,YAAY,IAAIJ,YAAY,CAAA;AAElC,IAAMK,UAAU,CAACC,SAAiBA,QAAQL,WAAWK,QAAQH;AAE7D,IAAMI,UAAU,CAACD,SAAiBA,QAAQJ,aAAaI,QAAQF;AAE/D,IAAMI,UAAU,CA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AA,IAAOO,SAAStB,KAAAA;QACzB,WAAWH,IAAI0B,iBAAiBP,KAAKK,GAAG,GAAG;AACzCP,iBAAOC,GAAAA,IAAOf,UAAU,UAAUA,UAAU;QAC9C,OAAO;AACLc,iBAAOC,GAAAA,IAAOf;QAChB;MACF;AAEA,aAAOc;IACT,GAAG,CAAC,CAAA;EACN;;;;EAKAU,OAAOjB,MAAcO,QAAgB;AACnC,UAAMN,MAAM,IAAIC,IAAIF,IAAAA;AACpBG,WAAOC,QAAQG,MAAAA,EAAQW,QAAQ,CAAC,CAACV,KAAKf,KAAAA,MAAM;AAC1C,UAAIA,UAAU0B,QAAW;AACvB,cAAMC,QAAQ,KAAKtB,QAAQO,OAAOG,GAAAA;AAClC,YAAIY,OAAO;AACT,gBAAM,EAAEZ,KAAKa,cAAa,IAAKC,KAC7BjC,sBAAsB+B,MAAMN,GAAG,GAC/BS,OAAOC,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;;;AExEA,SAAS0B,OAAAA,YAAW;AACpB,SAASC,UAAAA,SAAQC,QAAAA,aAAY;AAEtB,IAAMC,gBACX,CAAIC,iBACJ,CAACC,cACCC,MAAKC,KAAIJ,cAAiBC,YAAAA,EAAcC,SAAAA,GAAYG,QAAOC,cAAc;",
|
|
6
|
+
"names": ["AST", "JSONSchema", "Schema", "S", "AST", "Option", "pipe", "LOW_DASH", "codePointAt", "SMALL_A", "CAPITAL_A", "SMALL_Z", "CAPITAL_Z", "isLower", "char", "isUpper", "toLower", "decamelize", "str", "firstChar", "charCodeAt", "length", "changed", "out", "i", "c", "push", "String", "fromCharCode", "apply", "undefined", "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", "AST", "Option", "pipe", "getAnnotation", "annotationId", "annotated", "pipe", "AST", "Option", "getOrUndefined"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/common/effect/src/url.ts":{"bytes":
|
|
1
|
+
{"inputs":{"packages/common/effect/src/decamelize.ts":{"bytes":3867,"imports":[],"format":"esm"},"packages/common/effect/src/url.ts":{"bytes":7713,"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"packages/common/effect/src/decamelize.ts","kind":"import-statement","original":"./decamelize"}],"format":"esm"},"packages/common/effect/src/util.ts":{"bytes":1305,"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true}],"format":"esm"},"packages/common/effect/src/index.ts":{"bytes":1039,"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"packages/common/effect/src/url.ts","kind":"import-statement","original":"./url"},{"path":"packages/common/effect/src/util.ts","kind":"import-statement","original":"./util"}],"format":"esm"}},"outputs":{"packages/common/effect/dist/lib/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":6997},"packages/common/effect/dist/lib/node-esm/index.mjs":{"imports":[{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true},{"path":"@effect/schema","kind":"import-statement","external":true},{"path":"effect","kind":"import-statement","external":true}],"exports":["AST","JSONSchema","ParamKeyAnnotation","S","UrlParser","getAnnotation","getParamKeyAnnotation"],"entryPoint":"packages/common/effect/src/index.ts","inputs":{"packages/common/effect/src/index.ts":{"bytesInOutput":71},"packages/common/effect/src/url.ts":{"bytesInOutput":1550},"packages/common/effect/src/decamelize.ts":{"bytesInOutput":798},"packages/common/effect/src/util.ts":{"bytesInOutput":234}},"bytes":3102}}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decamelize.d.ts","sourceRoot":"","sources":["../../../src/decamelize.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,UAAU,QAAS,MAAM,WAmBrC,CAAC"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { AST, JSONSchema, Schema as S } from '@effect/schema';
|
|
2
|
-
|
|
2
|
+
import type * as Types from 'effect/Types';
|
|
3
|
+
export { AST, JSONSchema, S, Types };
|
|
3
4
|
export * from './url';
|
|
5
|
+
export * from './util';
|
|
4
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC;AAErC,cAAc,OAAO,CAAC;AACtB,cAAc,QAAQ,CAAC"}
|
package/dist/types/src/url.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { type Schema as S } from '@effect/schema';
|
|
1
|
+
import { AST, type Schema as S } from '@effect/schema';
|
|
2
|
+
import { Option } from 'effect';
|
|
2
3
|
type ParamKeyAnnotationValue = {
|
|
3
4
|
key: string;
|
|
4
5
|
};
|
|
6
|
+
export declare const getParamKeyAnnotation: (annotated: AST.Annotated) => Option.Option<ParamKeyAnnotationValue>;
|
|
5
7
|
export declare const ParamKeyAnnotation: (value: ParamKeyAnnotationValue) => <S extends S.Annotable.All>(self: S) => S.Annotable.Self<S>;
|
|
6
8
|
/**
|
|
7
9
|
* HTTP params parser.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../../src/url.ts"],"names":[],"mappings":"AAIA,OAAO,
|
|
1
|
+
{"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../../src/url.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,GAAG,EAAE,KAAK,MAAM,IAAI,CAAC,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAQ,MAAM,QAAQ,CAAC;AAMtC,KAAK,uBAAuB,GAAG;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAE/C,eAAO,MAAM,qBAAqB,EAAE,CAAC,SAAS,EAAE,GAAG,CAAC,SAAS,KAAK,MAAM,CAAC,MAAM,CAAC,uBAAuB,CACrC,CAAC;AAEnE,eAAO,MAAM,kBAAkB,UACrB,uBAAuB,MAC9B,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,GAAG,QAAQ,CAAC,KAAG,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CACH,CAAC;AAExD;;;GAGG;AACH,qBAAa,SAAS,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IACtC,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IAEjD;;OAEG;IACH,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC;IAsBtB;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,GAAG;CAoBrC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/util.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAGrC,eAAO,MAAM,aAAa,GACvB,CAAC,gBAAgB,MAAM,iBACZ,GAAG,CAAC,SAAS,KAAG,CAAC,GAAG,SAC4C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/effect",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.13-main.09887cd",
|
|
4
4
|
"description": "Effect utils.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -25,16 +25,15 @@
|
|
|
25
25
|
"src"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"
|
|
29
|
-
"@dxos/node-std": "0.6.12-staging.e11e696"
|
|
28
|
+
"@dxos/node-std": "0.6.13-main.09887cd"
|
|
30
29
|
},
|
|
31
30
|
"devDependencies": {
|
|
32
|
-
"@effect/schema": "^0.
|
|
33
|
-
"effect": "^3.
|
|
31
|
+
"@effect/schema": "^0.75.1",
|
|
32
|
+
"effect": "^3.9.1"
|
|
34
33
|
},
|
|
35
34
|
"peerDependencies": {
|
|
36
35
|
"@effect/schema": "^0.67.16",
|
|
37
|
-
"effect": "^3.
|
|
36
|
+
"effect": "^3.9.1"
|
|
38
37
|
},
|
|
39
38
|
"publishConfig": {
|
|
40
39
|
"access": "public"
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
const LOW_DASH = '_'.codePointAt(0)!;
|
|
6
|
+
const SMALL_A = 'a'.codePointAt(0)!;
|
|
7
|
+
const CAPITAL_A = 'A'.codePointAt(0)!;
|
|
8
|
+
const SMALL_Z = 'z'.codePointAt(0)!;
|
|
9
|
+
const CAPITAL_Z = 'Z'.codePointAt(0)!;
|
|
10
|
+
|
|
11
|
+
const isLower = (char: number) => char >= SMALL_A && char <= SMALL_Z;
|
|
12
|
+
|
|
13
|
+
const isUpper = (char: number) => char >= CAPITAL_A && char <= CAPITAL_Z;
|
|
14
|
+
|
|
15
|
+
const toLower = (char: number) => char + 0x20;
|
|
16
|
+
|
|
17
|
+
export const decamelize = (str: string) => {
|
|
18
|
+
const firstChar = str.charCodeAt(0);
|
|
19
|
+
if (!isLower(firstChar)) {
|
|
20
|
+
return str;
|
|
21
|
+
}
|
|
22
|
+
const length = str.length;
|
|
23
|
+
let changed = false;
|
|
24
|
+
const out: number[] = [];
|
|
25
|
+
for (let i = 0; i < length; ++i) {
|
|
26
|
+
const c = str.charCodeAt(i);
|
|
27
|
+
if (isUpper(c)) {
|
|
28
|
+
out.push(LOW_DASH);
|
|
29
|
+
out.push(toLower(c));
|
|
30
|
+
changed = true;
|
|
31
|
+
} else {
|
|
32
|
+
out.push(c);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return changed ? String.fromCharCode.apply(undefined, out) : str;
|
|
36
|
+
};
|
package/src/index.ts
CHANGED
package/src/url.ts
CHANGED
|
@@ -4,13 +4,14 @@
|
|
|
4
4
|
|
|
5
5
|
import { AST, type Schema as S } from '@effect/schema';
|
|
6
6
|
import { Option, pipe } from 'effect';
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
import { decamelize } from './decamelize';
|
|
8
9
|
|
|
9
10
|
const ParamKeyAnnotationId = Symbol.for('@dxos/schema/annotation/ParamKey');
|
|
10
11
|
|
|
11
12
|
type ParamKeyAnnotationValue = { key: string };
|
|
12
13
|
|
|
13
|
-
const getParamKeyAnnotation: (annotated: AST.Annotated) => Option.Option<ParamKeyAnnotationValue> =
|
|
14
|
+
export const getParamKeyAnnotation: (annotated: AST.Annotated) => Option.Option<ParamKeyAnnotationValue> =
|
|
14
15
|
AST.getAnnotation<ParamKeyAnnotationValue>(ParamKeyAnnotationId);
|
|
15
16
|
|
|
16
17
|
export const ParamKeyAnnotation =
|
package/src/util.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { AST } from '@effect/schema';
|
|
6
|
+
import { Option, pipe } from 'effect';
|
|
7
|
+
|
|
8
|
+
export const getAnnotation =
|
|
9
|
+
<T>(annotationId: symbol) =>
|
|
10
|
+
(annotated: AST.Annotated): T | undefined =>
|
|
11
|
+
pipe(AST.getAnnotation<T>(annotationId)(annotated), Option.getOrUndefined);
|