@dxos/util 0.6.13 → 0.6.14-main.1366248
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 +163 -150
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +156 -138
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +1998 -0
- package/dist/lib/node-esm/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -0
- package/dist/types/src/array-to-hex.d.ts +2 -0
- package/dist/types/src/array-to-hex.d.ts.map +1 -0
- package/dist/types/src/case.d.ts +3 -0
- package/dist/types/src/case.d.ts.map +1 -0
- package/dist/types/src/case.test.d.ts +2 -0
- package/dist/types/src/case.test.d.ts.map +1 -0
- package/dist/types/src/complex.d.ts +8 -8
- package/dist/types/src/complex.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +7 -3
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/map-values.d.ts +2 -2
- package/dist/types/src/map-values.d.ts.map +1 -1
- package/dist/types/src/platform.browser.test.d.ts +2 -0
- package/dist/types/src/platform.browser.test.d.ts.map +1 -0
- package/dist/types/src/platform.node.test.d.ts +2 -0
- package/dist/types/src/platform.node.test.d.ts.map +1 -0
- package/dist/types/src/random.d.ts +1 -1
- package/dist/types/src/random.d.ts.map +1 -1
- package/dist/types/src/remove-undefined-keys.d.ts +2 -0
- package/dist/types/src/remove-undefined-keys.d.ts.map +1 -0
- package/dist/types/src/weak.d.ts +4 -4
- package/dist/types/src/weak.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/array-to-hex.ts +23 -0
- package/src/array.test.ts +1 -2
- package/src/bitfield.test.ts +1 -2
- package/src/callback.test.ts +1 -2
- package/src/case.test.ts +14 -0
- package/src/case.ts +45 -0
- package/src/complex.test.ts +1 -2
- package/src/complex.ts +8 -8
- package/src/defer.test.ts +1 -2
- package/src/human-hash.test.ts +1 -2
- package/src/index.ts +7 -3
- package/src/join-tables.test.ts +1 -2
- package/src/map-values.ts +29 -10
- package/src/order.test.ts +1 -2
- package/src/platform.browser.test.ts +11 -0
- package/src/platform.node.test.ts +11 -0
- package/src/random.ts +1 -1
- package/src/reducers.test.ts +1 -2
- package/src/remove-undefined-keys.ts +13 -0
- package/src/safe-instanceof.test.ts +1 -2
- package/src/sort.test.ts +1 -2
- package/src/tracer.test.ts +3 -3
- package/src/types.test.ts +1 -2
- package/src/uint8array.test.ts +1 -2
- package/src/weak.test.ts +4 -8
- package/src/weak.ts +4 -4
- package/dist/types/src/params.d.ts +0 -22
- package/dist/types/src/params.d.ts.map +0 -1
- package/dist/types/src/params.test.d.ts +0 -2
- package/dist/types/src/params.test.d.ts.map +0 -1
- package/dist/types/src/platform.test.d.ts +0 -2
- package/dist/types/src/platform.test.d.ts.map +0 -1
- package/src/params.test.ts +0 -38
- package/src/params.ts +0 -68
- package/src/platform.test.ts +0 -17
- package/src/typings.d.ts +0 -5
package/src/params.test.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { Schema as S } from '@effect/schema';
|
|
6
|
-
import { expect } from 'chai';
|
|
7
|
-
import { describe, test } from 'vitest';
|
|
8
|
-
|
|
9
|
-
import { ParamKeyAnnotation, Params } from './params';
|
|
10
|
-
|
|
11
|
-
const InvitationUrl = S.Struct({
|
|
12
|
-
accessToken: S.String,
|
|
13
|
-
deviceInvitationCode: S.String.pipe(ParamKeyAnnotation('deviceInvitationCode')),
|
|
14
|
-
spaceInvitationCode: S.String,
|
|
15
|
-
experimental: S.Boolean,
|
|
16
|
-
timeout: S.Number,
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
describe('Params', () => {
|
|
20
|
-
test('parse', () => {
|
|
21
|
-
const props = new Params(InvitationUrl);
|
|
22
|
-
|
|
23
|
-
const values = props.parse(
|
|
24
|
-
new URL('http://localhost?access_token=100&deviceInvitationCode=200&experimental=1&timeout=100'),
|
|
25
|
-
);
|
|
26
|
-
expect(values).to.deep.eq({
|
|
27
|
-
accessToken: '100',
|
|
28
|
-
deviceInvitationCode: '200',
|
|
29
|
-
experimental: true,
|
|
30
|
-
timeout: 100,
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
const url = props.params(new URL('http://localhost'), values);
|
|
34
|
-
expect(url.toString()).to.eq(
|
|
35
|
-
'http://localhost/?access_token=100&deviceInvitationCode=200&experimental=true&timeout=100',
|
|
36
|
-
);
|
|
37
|
-
});
|
|
38
|
-
});
|
package/src/params.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { AST } from '@effect/schema';
|
|
6
|
-
// eslint-disable-next-line import/no-duplicates
|
|
7
|
-
import type * as S from '@effect/schema/Schema';
|
|
8
|
-
// eslint-disable-next-line import/no-duplicates
|
|
9
|
-
import { type Annotable } from '@effect/schema/Schema';
|
|
10
|
-
import { type Some } from 'effect/Option';
|
|
11
|
-
import { decamelize } from 'xcase';
|
|
12
|
-
|
|
13
|
-
// TODO(burdon): Change annotations.
|
|
14
|
-
|
|
15
|
-
type ParamKeyAnnotationType = string;
|
|
16
|
-
const ParamKeyAnnotationId = Symbol.for('@dxos/schema/annotation/ParamKeyAnnotation');
|
|
17
|
-
export const ParamKeyAnnotation =
|
|
18
|
-
(value: ParamKeyAnnotationType) =>
|
|
19
|
-
<S extends Annotable.All>(self: S): Annotable.Self<S> =>
|
|
20
|
-
self.annotations({ [ParamKeyAnnotationId]: value });
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* HTTP params parser.
|
|
24
|
-
*/
|
|
25
|
-
export class Params<T extends Record<string, any>> {
|
|
26
|
-
constructor(private readonly _schema: S.Struct<T>) {}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Parse URL params.
|
|
30
|
-
* @param url
|
|
31
|
-
*/
|
|
32
|
-
parse(url: URL): T {
|
|
33
|
-
return Object.entries(this._schema.fields).reduce<Record<string, any>>((acc, [key, type]) => {
|
|
34
|
-
let v = url.searchParams.get(decamelize(key));
|
|
35
|
-
if (v == null) {
|
|
36
|
-
v = url.searchParams.get(key);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (v != null) {
|
|
40
|
-
if (AST.isNumberKeyword(type.ast)) {
|
|
41
|
-
acc[key] = parseInt(v);
|
|
42
|
-
} else if (AST.isBooleanKeyword(type.ast)) {
|
|
43
|
-
acc[key] = v === 'true' || v === '1';
|
|
44
|
-
} else {
|
|
45
|
-
acc[key] = v;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return acc;
|
|
50
|
-
}, {}) as T;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Update URL with params.
|
|
55
|
-
*/
|
|
56
|
-
params(url: URL, values: T): URL {
|
|
57
|
-
Object.entries(values).forEach(([key, value]) => {
|
|
58
|
-
const type = this._schema.fields[key];
|
|
59
|
-
if (type && value != null) {
|
|
60
|
-
const { value: alt } = AST.getAnnotation(ParamKeyAnnotationId)(type.ast) as Some<ParamKeyAnnotationType>;
|
|
61
|
-
const k = alt ?? decamelize(key);
|
|
62
|
-
url.searchParams.set(k, String(value));
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
return url;
|
|
67
|
-
}
|
|
68
|
-
}
|
package/src/platform.test.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2020 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { expect } from 'chai';
|
|
6
|
-
import { test } from 'vitest';
|
|
7
|
-
|
|
8
|
-
import { isNode } from './platform';
|
|
9
|
-
|
|
10
|
-
// TODO(dmaretskyi): Broken with vitest conversion.
|
|
11
|
-
test.skip('knows when running in node', () => {
|
|
12
|
-
if (mochaExecutor.environment === 'nodejs') {
|
|
13
|
-
expect(isNode()).to.be.true;
|
|
14
|
-
} else {
|
|
15
|
-
expect(isNode()).to.be.false;
|
|
16
|
-
}
|
|
17
|
-
});
|