@dxos/echo 0.8.4-main.5ea62a8 → 0.8.4-main.66e292d
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/chunk-7GH6RXJ3.mjs +3683 -0
- package/dist/lib/browser/chunk-7GH6RXJ3.mjs.map +7 -0
- package/dist/lib/browser/chunk-E4UTVJNF.mjs +1111 -0
- package/dist/lib/browser/chunk-E4UTVJNF.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +24 -1
- package/dist/lib/browser/internal/index.mjs +336 -0
- package/dist/lib/browser/internal/index.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +289 -31
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/node-esm/chunk-JE5RXM2I.mjs +1111 -0
- package/dist/lib/node-esm/chunk-JE5RXM2I.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-M4B6BMD2.mjs +3683 -0
- package/dist/lib/node-esm/chunk-M4B6BMD2.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +24 -1
- package/dist/lib/node-esm/internal/index.mjs +336 -0
- package/dist/lib/node-esm/internal/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +289 -31
- package/dist/lib/node-esm/testing/index.mjs.map +4 -4
- package/dist/types/src/Annotation.d.ts +2 -0
- package/dist/types/src/Annotation.d.ts.map +1 -0
- package/dist/types/src/Database.d.ts +137 -0
- package/dist/types/src/Database.d.ts.map +1 -0
- package/dist/types/src/Entity.d.ts +36 -0
- package/dist/types/src/Entity.d.ts.map +1 -0
- package/dist/types/src/Format.d.ts +4 -0
- package/dist/types/src/Format.d.ts.map +1 -0
- package/dist/types/src/JsonSchema.d.ts +9 -0
- package/dist/types/src/JsonSchema.d.ts.map +1 -0
- package/dist/types/src/Key.d.ts +1 -0
- package/dist/types/src/Key.d.ts.map +1 -1
- package/dist/types/src/Obj.d.ts +121 -50
- package/dist/types/src/Obj.d.ts.map +1 -1
- package/dist/types/src/Ref.d.ts +10 -10
- package/dist/types/src/Ref.d.ts.map +1 -1
- package/dist/types/src/Relation.d.ts +18 -14
- package/dist/types/src/Relation.d.ts.map +1 -1
- package/dist/types/src/Tag.d.ts +17 -0
- package/dist/types/src/Tag.d.ts.map +1 -0
- package/dist/types/src/Type.d.ts +39 -50
- package/dist/types/src/Type.d.ts.map +1 -1
- package/dist/types/src/errors.d.ts +68 -0
- package/dist/types/src/errors.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +9 -3
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/internal/annotations/annotations.d.ts +174 -0
- package/dist/types/src/internal/annotations/annotations.d.ts.map +1 -0
- package/dist/types/src/internal/annotations/annotations.test.d.ts +2 -0
- package/dist/types/src/internal/annotations/annotations.test.d.ts.map +1 -0
- package/dist/types/src/internal/annotations/index.d.ts +3 -0
- package/dist/types/src/internal/annotations/index.d.ts.map +1 -0
- package/dist/types/src/internal/annotations/util.d.ts +26 -0
- package/dist/types/src/internal/annotations/util.d.ts.map +1 -0
- package/dist/types/src/internal/entities/entity.d.ts +10 -0
- package/dist/types/src/internal/entities/entity.d.ts.map +1 -0
- package/dist/types/src/internal/entities/expando.d.ts +16 -0
- package/dist/types/src/internal/entities/expando.d.ts.map +1 -0
- package/dist/types/src/internal/entities/index.d.ts +6 -0
- package/dist/types/src/internal/entities/index.d.ts.map +1 -0
- package/dist/types/src/internal/entities/model.d.ts +70 -0
- package/dist/types/src/internal/entities/model.d.ts.map +1 -0
- package/dist/types/src/internal/entities/object.d.ts +11 -0
- package/dist/types/src/internal/entities/object.d.ts.map +1 -0
- package/dist/types/src/internal/entities/relation.d.ts +55 -0
- package/dist/types/src/internal/entities/relation.d.ts.map +1 -0
- package/dist/types/src/internal/entities/util.d.ts +2 -0
- package/dist/types/src/internal/entities/util.d.ts.map +1 -0
- package/dist/types/src/internal/formats/date.d.ts +63 -0
- package/dist/types/src/internal/formats/date.d.ts.map +1 -0
- package/dist/types/src/internal/formats/date.test.d.ts +2 -0
- package/dist/types/src/internal/formats/date.test.d.ts.map +1 -0
- package/dist/types/src/internal/formats/format.d.ts +32 -0
- package/dist/types/src/internal/formats/format.d.ts.map +1 -0
- package/dist/types/src/internal/formats/format.test.d.ts +2 -0
- package/dist/types/src/internal/formats/format.test.d.ts.map +1 -0
- package/dist/types/src/internal/formats/index.d.ts +8 -0
- package/dist/types/src/internal/formats/index.d.ts.map +1 -0
- package/dist/types/src/internal/formats/number.d.ts +31 -0
- package/dist/types/src/internal/formats/number.d.ts.map +1 -0
- package/dist/types/src/internal/formats/object.d.ts +35 -0
- package/dist/types/src/internal/formats/object.d.ts.map +1 -0
- package/dist/types/src/internal/formats/select.d.ts +11 -0
- package/dist/types/src/internal/formats/select.d.ts.map +1 -0
- package/dist/types/src/internal/formats/string.d.ts +38 -0
- package/dist/types/src/internal/formats/string.d.ts.map +1 -0
- package/dist/types/src/internal/formats/types.d.ts +68 -0
- package/dist/types/src/internal/formats/types.d.ts.map +1 -0
- package/dist/types/src/internal/index.d.ts +11 -0
- package/dist/types/src/internal/index.d.ts.map +1 -0
- package/dist/types/src/internal/json-schema/annotations.d.ts +19 -0
- package/dist/types/src/internal/json-schema/annotations.d.ts.map +1 -0
- package/dist/types/src/internal/json-schema/effect-schema.test.d.ts +2 -0
- package/dist/types/src/internal/json-schema/effect-schema.test.d.ts.map +1 -0
- package/dist/types/src/internal/json-schema/index.d.ts +5 -0
- package/dist/types/src/internal/json-schema/index.d.ts.map +1 -0
- package/dist/types/src/internal/json-schema/json-schema-normalize.d.ts +7 -0
- package/dist/types/src/internal/json-schema/json-schema-normalize.d.ts.map +1 -0
- package/dist/types/src/internal/json-schema/json-schema-type.d.ts +250 -0
- package/dist/types/src/internal/json-schema/json-schema-type.d.ts.map +1 -0
- package/dist/types/src/internal/json-schema/json-schema.d.ts +29 -0
- package/dist/types/src/internal/json-schema/json-schema.d.ts.map +1 -0
- package/dist/types/src/internal/json-schema/json-schema.test.d.ts +2 -0
- package/dist/types/src/internal/json-schema/json-schema.test.d.ts.map +1 -0
- package/dist/types/src/internal/object/common.d.ts +18 -0
- package/dist/types/src/internal/object/common.d.ts.map +1 -0
- package/dist/types/src/internal/object/create-object.d.ts +39 -0
- package/dist/types/src/internal/object/create-object.d.ts.map +1 -0
- package/dist/types/src/internal/object/create-object.test.d.ts +2 -0
- package/dist/types/src/internal/object/create-object.test.d.ts.map +1 -0
- package/dist/types/src/internal/object/deleted.d.ts +6 -0
- package/dist/types/src/internal/object/deleted.d.ts.map +1 -0
- package/dist/types/src/internal/object/ids.d.ts +6 -0
- package/dist/types/src/internal/object/ids.d.ts.map +1 -0
- package/dist/types/src/internal/object/index.d.ts +8 -0
- package/dist/types/src/internal/object/index.d.ts.map +1 -0
- package/dist/types/src/internal/object/inspect.d.ts +2 -0
- package/dist/types/src/internal/object/inspect.d.ts.map +1 -0
- package/dist/types/src/internal/object/json-serializer.d.ts +31 -0
- package/dist/types/src/internal/object/json-serializer.d.ts.map +1 -0
- package/dist/types/src/internal/object/json-serializer.test.d.ts +2 -0
- package/dist/types/src/internal/object/json-serializer.test.d.ts.map +1 -0
- package/dist/types/src/internal/object/schema-validator.d.ts +15 -0
- package/dist/types/src/internal/object/schema-validator.d.ts.map +1 -0
- package/dist/types/src/internal/object/schema-validator.test.d.ts +2 -0
- package/dist/types/src/internal/object/schema-validator.test.d.ts.map +1 -0
- package/dist/types/src/internal/object/typed-object.d.ts +31 -0
- package/dist/types/src/internal/object/typed-object.d.ts.map +1 -0
- package/dist/types/src/internal/object/typed-object.test.d.ts +2 -0
- package/dist/types/src/internal/object/typed-object.test.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/handler.test.d.ts +2 -0
- package/dist/types/src/internal/proxy/handler.test.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/index.d.ts +3 -0
- package/dist/types/src/internal/proxy/index.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/make-object.d.ts +16 -0
- package/dist/types/src/internal/proxy/make-object.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/schema.test.d.ts +2 -0
- package/dist/types/src/internal/proxy/schema.test.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/typed-handler.d.ts +44 -0
- package/dist/types/src/internal/proxy/typed-handler.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/typed-handler.test.d.ts +2 -0
- package/dist/types/src/internal/proxy/typed-handler.test.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/typed-object.test.d.ts +2 -0
- package/dist/types/src/internal/proxy/typed-object.test.d.ts.map +1 -0
- package/dist/types/src/internal/ref/index.d.ts +3 -0
- package/dist/types/src/internal/ref/index.d.ts.map +1 -0
- package/dist/types/src/internal/ref/ref-array.d.ts +21 -0
- package/dist/types/src/internal/ref/ref-array.d.ts.map +1 -0
- package/dist/types/src/internal/ref/ref.d.ts +209 -0
- package/dist/types/src/internal/ref/ref.d.ts.map +1 -0
- package/dist/types/src/internal/ref/ref.test.d.ts +2 -0
- package/dist/types/src/internal/ref/ref.test.d.ts.map +1 -0
- package/dist/types/src/internal/schema/compose.d.ts +6 -0
- package/dist/types/src/internal/schema/compose.d.ts.map +1 -0
- package/dist/types/src/internal/schema/compose.test.d.ts +2 -0
- package/dist/types/src/internal/schema/compose.test.d.ts.map +1 -0
- package/dist/types/src/internal/schema/echo-schema.d.ts +168 -0
- package/dist/types/src/internal/schema/echo-schema.d.ts.map +1 -0
- package/dist/types/src/internal/schema/index.d.ts +6 -0
- package/dist/types/src/internal/schema/index.d.ts.map +1 -0
- package/dist/types/src/internal/schema/manipulation.d.ts +10 -0
- package/dist/types/src/internal/schema/manipulation.d.ts.map +1 -0
- package/dist/types/src/internal/schema/persistent-schema.d.ts +18 -0
- package/dist/types/src/internal/schema/persistent-schema.d.ts.map +1 -0
- package/dist/types/src/internal/schema/runtime-schema-registry.d.ts +18 -0
- package/dist/types/src/internal/schema/runtime-schema-registry.d.ts.map +1 -0
- package/dist/types/src/internal/schema/snapshot.d.ts +6 -0
- package/dist/types/src/internal/schema/snapshot.d.ts.map +1 -0
- package/dist/types/src/internal/types/base.d.ts +37 -0
- package/dist/types/src/internal/types/base.d.ts.map +1 -0
- package/dist/types/src/internal/types/entity.d.ts +12 -0
- package/dist/types/src/internal/types/entity.d.ts.map +1 -0
- package/dist/types/src/internal/types/index.d.ts +6 -0
- package/dist/types/src/internal/types/index.d.ts.map +1 -0
- package/dist/types/src/internal/types/meta.d.ts +40 -0
- package/dist/types/src/internal/types/meta.d.ts.map +1 -0
- package/dist/types/src/internal/types/typename.d.ts +13 -0
- package/dist/types/src/internal/types/typename.d.ts.map +1 -0
- package/dist/types/src/internal/types/version.d.ts +15 -0
- package/dist/types/src/internal/types/version.d.ts.map +1 -0
- package/dist/types/src/query/filter.d.ts +167 -0
- package/dist/types/src/query/filter.d.ts.map +1 -0
- package/dist/types/src/query/index.d.ts +4 -1
- package/dist/types/src/query/index.d.ts.map +1 -1
- package/dist/types/src/query/order.d.ts +12 -0
- package/dist/types/src/query/order.d.ts.map +1 -0
- package/dist/types/src/query/query.d.ts +112 -0
- package/dist/types/src/query/query.d.ts.map +1 -0
- package/dist/types/src/query/query.test.d.ts +2 -0
- package/dist/types/src/query/query.test.d.ts.map +1 -0
- package/dist/types/src/query/testing.d.ts +51 -0
- package/dist/types/src/query/testing.d.ts.map +1 -0
- package/dist/types/src/query/types.d.ts +17 -0
- package/dist/types/src/query/types.d.ts.map +1 -0
- package/dist/types/src/query/util.d.ts +8 -0
- package/dist/types/src/query/util.d.ts.map +1 -0
- package/dist/types/src/{test → testing}/api.test.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +3 -1
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/test-data.d.ts +18 -0
- package/dist/types/src/testing/test-data.d.ts.map +1 -0
- package/dist/types/src/testing/test-schema.d.ts +337 -0
- package/dist/types/src/testing/test-schema.d.ts.map +1 -0
- package/dist/types/src/testing/util.d.ts +16 -0
- package/dist/types/src/testing/util.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +49 -29
- package/src/Annotation.ts +17 -0
- package/src/Database.ts +189 -0
- package/src/Entity.ts +51 -0
- package/src/Format.ts +11 -0
- package/src/JsonSchema.ts +16 -0
- package/src/Key.ts +3 -0
- package/src/Obj.ts +353 -107
- package/src/Ref.ts +9 -10
- package/src/Relation.ts +68 -43
- package/src/Tag.ts +40 -0
- package/src/Type.ts +97 -85
- package/src/errors.ts +18 -0
- package/src/index.ts +13 -4
- package/src/internal/README.md +83 -0
- package/src/internal/annotations/annotations.test.ts +96 -0
- package/src/internal/annotations/annotations.ts +463 -0
- package/src/internal/annotations/index.ts +6 -0
- package/src/internal/annotations/util.ts +70 -0
- package/src/internal/entities/entity.ts +109 -0
- package/src/internal/entities/expando.ts +23 -0
- package/src/internal/entities/index.ts +9 -0
- package/src/internal/entities/model.ts +129 -0
- package/src/internal/entities/object.ts +45 -0
- package/src/internal/entities/relation.ts +155 -0
- package/src/internal/entities/util.ts +33 -0
- package/src/internal/formats/date.test.ts +56 -0
- package/src/internal/formats/date.ts +217 -0
- package/src/internal/formats/format.test.ts +77 -0
- package/src/internal/formats/format.ts +55 -0
- package/src/internal/formats/index.ts +12 -0
- package/src/internal/formats/number.ts +89 -0
- package/src/internal/formats/object.ts +80 -0
- package/src/internal/formats/select.ts +16 -0
- package/src/internal/formats/string.ts +76 -0
- package/src/internal/formats/types.ts +180 -0
- package/src/internal/index.ts +38 -0
- package/src/internal/json-schema/annotations.ts +50 -0
- package/src/internal/json-schema/effect-schema.test.ts +143 -0
- package/src/internal/json-schema/index.ts +8 -0
- package/src/internal/json-schema/json-schema-normalize.ts +109 -0
- package/src/internal/json-schema/json-schema-type.ts +404 -0
- package/src/internal/json-schema/json-schema.test.ts +859 -0
- package/src/internal/json-schema/json-schema.ts +528 -0
- package/src/internal/object/common.ts +75 -0
- package/src/internal/object/create-object.test.ts +116 -0
- package/src/internal/object/create-object.ts +95 -0
- package/src/internal/object/deleted.ts +19 -0
- package/src/internal/object/ids.ts +12 -0
- package/src/internal/object/index.ts +11 -0
- package/src/internal/object/inspect.ts +46 -0
- package/src/internal/object/json-serializer.test.ts +94 -0
- package/src/internal/object/json-serializer.ts +230 -0
- package/src/internal/object/schema-validator.test.ts +186 -0
- package/src/internal/object/schema-validator.ts +242 -0
- package/src/internal/object/typed-object.test.ts +34 -0
- package/src/internal/object/typed-object.ts +94 -0
- package/src/internal/proxy/handler.test.ts +173 -0
- package/src/internal/proxy/index.ts +6 -0
- package/src/internal/proxy/make-object.ts +113 -0
- package/src/internal/proxy/schema.test.ts +137 -0
- package/src/internal/proxy/typed-handler.test.ts +102 -0
- package/src/internal/proxy/typed-handler.ts +233 -0
- package/src/internal/proxy/typed-object.test.ts +105 -0
- package/src/internal/ref/index.ts +6 -0
- package/src/internal/ref/ref-array.ts +39 -0
- package/src/internal/ref/ref.test.ts +101 -0
- package/src/internal/ref/ref.ts +525 -0
- package/src/internal/schema/compose.test.ts +42 -0
- package/src/internal/schema/compose.ts +37 -0
- package/src/internal/schema/echo-schema.ts +385 -0
- package/src/internal/schema/index.ts +9 -0
- package/src/internal/schema/manipulation.ts +92 -0
- package/src/internal/schema/persistent-schema.ts +28 -0
- package/src/internal/schema/runtime-schema-registry.ts +78 -0
- package/src/internal/schema/snapshot.ts +25 -0
- package/src/internal/types/base.ts +58 -0
- package/src/internal/types/entity.ts +23 -0
- package/src/internal/types/index.ts +9 -0
- package/src/internal/types/meta.ts +76 -0
- package/src/internal/types/typename.ts +45 -0
- package/src/internal/types/version.ts +20 -0
- package/src/query/filter.ts +455 -0
- package/src/query/index.ts +5 -1
- package/src/query/order.ts +34 -0
- package/src/query/query.test.ts +334 -0
- package/src/query/query.ts +303 -0
- package/src/query/testing.ts +64 -0
- package/src/query/types.ts +23 -0
- package/src/query/util.ts +25 -0
- package/src/testing/api.test.ts +100 -0
- package/src/testing/index.ts +3 -1
- package/src/testing/test-data.ts +130 -0
- package/src/testing/test-schema.ts +213 -0
- package/src/testing/util.ts +78 -0
- package/dist/lib/browser/chunk-2KNTYMIW.mjs +0 -697
- package/dist/lib/browser/chunk-2KNTYMIW.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-EXNNC62J.mjs +0 -697
- package/dist/lib/node-esm/chunk-EXNNC62J.mjs.map +0 -7
- package/dist/types/src/experimental/database.d.ts +0 -8
- package/dist/types/src/experimental/database.d.ts.map +0 -1
- package/dist/types/src/experimental/index.d.ts +0 -1
- package/dist/types/src/experimental/index.d.ts.map +0 -1
- package/dist/types/src/experimental/queue.d.ts +0 -8
- package/dist/types/src/experimental/queue.d.ts.map +0 -1
- package/dist/types/src/experimental/space.d.ts +0 -8
- package/dist/types/src/experimental/space.d.ts.map +0 -1
- package/dist/types/src/query/dsl.d.ts +0 -218
- package/dist/types/src/query/dsl.d.ts.map +0 -1
- package/dist/types/src/query/dsl.test.d.ts +0 -2
- package/dist/types/src/query/dsl.test.d.ts.map +0 -1
- package/dist/types/src/testing/types.d.ts +0 -113
- package/dist/types/src/testing/types.d.ts.map +0 -1
- package/src/experimental/database.ts +0 -11
- package/src/experimental/index.ts +0 -7
- package/src/experimental/queue.ts +0 -11
- package/src/experimental/space.ts +0 -11
- package/src/query/dsl.test.ts +0 -324
- package/src/query/dsl.ts +0 -646
- package/src/test/api.test.ts +0 -173
- package/src/testing/types.ts +0 -91
- /package/dist/types/src/{test → testing}/api.test.d.ts +0 -0
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
7
|
+
|
|
8
|
+
import { FormatAnnotation, TypeFormat } from './types';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Datetime values should be stored as ISO strings or unix numbers (ms) in UTC.
|
|
12
|
+
*
|
|
13
|
+
* NOTE: HyperFormula uses Excel's time format (null date 1900/01/01)
|
|
14
|
+
* It can be configured to use a different parser via `parseDateTime`.
|
|
15
|
+
* https://hyperformula.handsontable.com/guide/date-and-time-handling.html#date-and-time-handling
|
|
16
|
+
* https://github.com/handsontable/hyperformula/blob/master/src/DateTimeHelper.ts
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
// TODO(burdon): Annotations not present in JSON.
|
|
20
|
+
// TODO(burdon): Timezone.
|
|
21
|
+
// TODO(burdon): Format for timestamp (Unix UTC or ISO 8601)?
|
|
22
|
+
// TODO(burdon): Refs
|
|
23
|
+
// - https://www.npmjs.com/package/numfmt
|
|
24
|
+
// - https://date-fns.org/docs/Getting-Started
|
|
25
|
+
// - https://github.com/date-fns/tz
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Simple date compatible with HF.
|
|
29
|
+
*/
|
|
30
|
+
export const SimpleDate = Schema.Struct({
|
|
31
|
+
year: Schema.Number.pipe(Schema.between(1900, 9999)),
|
|
32
|
+
month: Schema.Number.pipe(Schema.between(1, 12)),
|
|
33
|
+
day: Schema.Number.pipe(Schema.between(1, 31)),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export type SimpleDate = Schema.Schema.Type<typeof SimpleDate>;
|
|
37
|
+
|
|
38
|
+
export const toSimpleDate = (date: Date): SimpleDate => ({
|
|
39
|
+
year: date.getUTCFullYear(),
|
|
40
|
+
month: date.getUTCMonth() + 1,
|
|
41
|
+
day: date.getUTCDate(),
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Simple time compatible with HF.
|
|
46
|
+
*/
|
|
47
|
+
export const SimpleTime = Schema.Struct({
|
|
48
|
+
hours: Schema.Number.pipe(Schema.between(0, 23)),
|
|
49
|
+
minutes: Schema.Number.pipe(Schema.between(0, 59)),
|
|
50
|
+
seconds: Schema.Number.pipe(Schema.between(0, 59)),
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
export type SimpleTime = Schema.Schema.Type<typeof SimpleTime>;
|
|
54
|
+
|
|
55
|
+
export const toSimpleTime = (date: Date): SimpleTime => ({
|
|
56
|
+
hours: date.getUTCHours(),
|
|
57
|
+
minutes: date.getUTCSeconds(),
|
|
58
|
+
seconds: date.getUTCSeconds(),
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Simple date-time compatible with HF.
|
|
63
|
+
*/
|
|
64
|
+
export const SimpleDateTime = Schema.extend(SimpleDate, SimpleTime);
|
|
65
|
+
|
|
66
|
+
export type SimpleDateTime = Schema.Schema.Type<typeof SimpleDateTime>;
|
|
67
|
+
|
|
68
|
+
export const toSimpleDateTime = (date: Date): SimpleDateTime => ({
|
|
69
|
+
...toSimpleDate(date),
|
|
70
|
+
...toSimpleTime(date),
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* https://effect.website/docs/guides/schema/transformations#date-transformations
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
// TODO(burdon): Consider if transformations should be supported with Automerge.
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Format: 2018-11-13
|
|
81
|
+
*/
|
|
82
|
+
export const DateOnly = /* Schema.transformOrFail(Schema.String, SimpleDate, {
|
|
83
|
+
strict: true,
|
|
84
|
+
decode: (str, _, ast) => {
|
|
85
|
+
if (!isValidDateFormat(str)) {
|
|
86
|
+
return ParseResult.fail(new ParseResult.Type(ast, str, 'Expected YYYY-MM-DD format'));
|
|
87
|
+
}
|
|
88
|
+
if (!isValidDate(str)) {
|
|
89
|
+
return ParseResult.fail(new ParseResult.Type(ast, str, 'Invalid date'));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const [year, month, day] = str.split('-').map(Number);
|
|
93
|
+
return ParseResult.succeed({ year, month, day });
|
|
94
|
+
},
|
|
95
|
+
encode: (date) => {
|
|
96
|
+
return ParseResult.succeed(
|
|
97
|
+
[
|
|
98
|
+
date.year.toString().padStart(4, '0'),
|
|
99
|
+
date.month.toString().padStart(2, '0'),
|
|
100
|
+
date.day.toString().padStart(2, '0'),
|
|
101
|
+
].join('-'),
|
|
102
|
+
);
|
|
103
|
+
},
|
|
104
|
+
}) */ Schema.String.pipe(
|
|
105
|
+
FormatAnnotation.set(TypeFormat.Date),
|
|
106
|
+
Schema.annotations({
|
|
107
|
+
title: 'Date',
|
|
108
|
+
description: 'Valid date in ISO format',
|
|
109
|
+
}),
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Format: 20:20:39+00:00
|
|
114
|
+
*/
|
|
115
|
+
export const TimeOnly = /* Schema.transformOrFail(Schema.String, SimpleTime, {
|
|
116
|
+
strict: true,
|
|
117
|
+
decode: (str, _, ast) => {
|
|
118
|
+
if (!isValidTimeFormat(str)) {
|
|
119
|
+
return ParseResult.fail(new ParseResult.Type(ast, str, 'Expected HH:mm:ss format'));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const [hours, minutes, seconds] = str.split(':').map(Number);
|
|
123
|
+
return ParseResult.succeed({ hours, minutes, seconds });
|
|
124
|
+
},
|
|
125
|
+
encode: (time) => {
|
|
126
|
+
return ParseResult.succeed(
|
|
127
|
+
[
|
|
128
|
+
time.hours.toString().padStart(2, '0'),
|
|
129
|
+
time.minutes.toString().padStart(2, '0'),
|
|
130
|
+
time.seconds.toString().padStart(2, '0'),
|
|
131
|
+
].join(':'),
|
|
132
|
+
);
|
|
133
|
+
},
|
|
134
|
+
}) */ Schema.String.pipe(
|
|
135
|
+
FormatAnnotation.set(TypeFormat.Time),
|
|
136
|
+
Schema.annotations({
|
|
137
|
+
title: 'Time',
|
|
138
|
+
description: 'Valid time in ISO format',
|
|
139
|
+
}),
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Format: 2018-11-13T20:20:39+00:00
|
|
144
|
+
*/
|
|
145
|
+
export const DateTime = /* Schema.transformOrFail(Schema.String, SimpleDateTime, {
|
|
146
|
+
strict: false,
|
|
147
|
+
decode: (str, _, ast) => {
|
|
148
|
+
const [date, time] = str.split('T');
|
|
149
|
+
if (!isValidDateFormat(date)) {
|
|
150
|
+
return ParseResult.fail(new ParseResult.Type(ast, date, 'Expected YYYY-MM-DD format'));
|
|
151
|
+
}
|
|
152
|
+
if (!isValidDate(date)) {
|
|
153
|
+
return ParseResult.fail(new ParseResult.Type(ast, date, 'Invalid date'));
|
|
154
|
+
}
|
|
155
|
+
if (!isValidTimeFormat(time)) {
|
|
156
|
+
return ParseResult.fail(new ParseResult.Type(ast, str, 'Expected HH:mm:ss format'));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const [year, month, day] = date.split('-').map(Number);
|
|
160
|
+
const [hours, minutes, seconds] = time.split(':').map(Number);
|
|
161
|
+
return ParseResult.succeed({ year, month, day, hours, minutes, seconds });
|
|
162
|
+
},
|
|
163
|
+
encode: (datetime) => {
|
|
164
|
+
return ParseResult.succeed(
|
|
165
|
+
[
|
|
166
|
+
[
|
|
167
|
+
datetime.year.toString().padStart(4, '0'),
|
|
168
|
+
datetime.month.toString().padStart(2, '0'),
|
|
169
|
+
datetime.day.toString().padStart(2, '0'),
|
|
170
|
+
].join('-'),
|
|
171
|
+
[
|
|
172
|
+
datetime.hours.toString().padStart(2, '0'),
|
|
173
|
+
datetime.minutes.toString().padStart(2, '0'),
|
|
174
|
+
datetime.seconds.toString().padStart(2, '0'),
|
|
175
|
+
].join(':'),
|
|
176
|
+
].join('T'),
|
|
177
|
+
);
|
|
178
|
+
},
|
|
179
|
+
}) */ Schema.String.pipe(
|
|
180
|
+
FormatAnnotation.set(TypeFormat.DateTime),
|
|
181
|
+
Schema.annotations({
|
|
182
|
+
title: 'DateTime',
|
|
183
|
+
description: 'Valid date and time in ISO format',
|
|
184
|
+
}),
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* https://datatracker.ietf.org/doc/html/rfc3339#appendix-A
|
|
189
|
+
*/
|
|
190
|
+
// TODO(burdon): Define duration type.
|
|
191
|
+
export const Duration = Schema.String.pipe(
|
|
192
|
+
FormatAnnotation.set(TypeFormat.Duration),
|
|
193
|
+
Schema.annotations({
|
|
194
|
+
title: 'Duration',
|
|
195
|
+
description: 'Duration in ISO 8601 format',
|
|
196
|
+
[SchemaAST.ExamplesAnnotationId]: ['1h', '3D'],
|
|
197
|
+
}),
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
//
|
|
201
|
+
// Utils
|
|
202
|
+
//
|
|
203
|
+
|
|
204
|
+
// YYYY-MM-DD
|
|
205
|
+
const DATE_REGEX = /^\d{4}-\d{2}-\d{2}$/;
|
|
206
|
+
|
|
207
|
+
const _isValidDateFormat = (str: string) => DATE_REGEX.test(str);
|
|
208
|
+
|
|
209
|
+
const _isValidDate = (str: string) => {
|
|
210
|
+
const date = new Date(str);
|
|
211
|
+
return !isNaN(date.getTime()) && date.toISOString().startsWith(str);
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
// HH:mm:ss
|
|
215
|
+
const TIME_REGEX = /^([01]\d|2[0-3]):([0-5]\d):([0-5]\d)$/;
|
|
216
|
+
|
|
217
|
+
const _isValidTimeFormat = (str: string) => TIME_REGEX.test(str);
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
import { describe, test } from 'vitest';
|
|
7
|
+
|
|
8
|
+
import { toJsonSchema } from '../json-schema';
|
|
9
|
+
|
|
10
|
+
import { Format } from './format';
|
|
11
|
+
import { TypeEnum, TypeFormat, getTypeEnum } from './types';
|
|
12
|
+
|
|
13
|
+
describe('formats', () => {
|
|
14
|
+
test('annotations', ({ expect }) => {
|
|
15
|
+
const TestSchema = Schema.Struct({
|
|
16
|
+
name: Schema.String,
|
|
17
|
+
email: Schema.optional(Format.Email),
|
|
18
|
+
salary: Schema.optional(Format.Currency({ decimals: 2, code: 'usd' })),
|
|
19
|
+
website: Schema.optional(Format.URL),
|
|
20
|
+
birthday: Schema.optional(Format.Date),
|
|
21
|
+
started: Schema.optional(Format.DateTime),
|
|
22
|
+
active: Schema.optional(Schema.Boolean),
|
|
23
|
+
}).pipe(Schema.mutable);
|
|
24
|
+
|
|
25
|
+
type TestType = Schema.Schema.Type<typeof TestSchema>;
|
|
26
|
+
|
|
27
|
+
const jsonSchema = toJsonSchema(TestSchema);
|
|
28
|
+
|
|
29
|
+
const data: TestType = {
|
|
30
|
+
name: 'Alice',
|
|
31
|
+
email: 'alice@example.com',
|
|
32
|
+
birthday: '1999-06-11',
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const validate = Schema.validateSync(TestSchema);
|
|
36
|
+
validate(data);
|
|
37
|
+
|
|
38
|
+
{
|
|
39
|
+
const prop = jsonSchema.properties!['active' as const];
|
|
40
|
+
expect(getTypeEnum(prop)).to.eq(TypeEnum.Boolean);
|
|
41
|
+
expect(prop).includes({
|
|
42
|
+
type: TypeEnum.Boolean,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
{
|
|
47
|
+
const prop = jsonSchema.properties!['email' as const];
|
|
48
|
+
expect(getTypeEnum(prop)).to.eq(TypeEnum.String);
|
|
49
|
+
expect(prop).includes({
|
|
50
|
+
type: TypeEnum.String,
|
|
51
|
+
format: TypeFormat.Email,
|
|
52
|
+
title: 'Email',
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
{
|
|
57
|
+
const prop = jsonSchema.properties!['salary' as const];
|
|
58
|
+
expect(getTypeEnum(prop)).to.eq(TypeEnum.Number);
|
|
59
|
+
expect(prop).includes({
|
|
60
|
+
type: TypeEnum.Number,
|
|
61
|
+
format: TypeFormat.Currency,
|
|
62
|
+
title: 'Currency',
|
|
63
|
+
multipleOf: 0.01,
|
|
64
|
+
currency: 'USD',
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
{
|
|
69
|
+
const prop = jsonSchema.properties!['birthday' as const];
|
|
70
|
+
expect(getTypeEnum(prop)).to.eq(TypeEnum.String);
|
|
71
|
+
expect(prop).includes({
|
|
72
|
+
type: TypeEnum.String,
|
|
73
|
+
format: TypeFormat.Date,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
|
|
7
|
+
import * as Keys from '@dxos/keys';
|
|
8
|
+
|
|
9
|
+
import * as DateUtil from './date';
|
|
10
|
+
import * as NumberUtil from './number';
|
|
11
|
+
import * as ObjectUtil from './object';
|
|
12
|
+
import * as StringUtil from './string';
|
|
13
|
+
import { TypeFormat as TypeFormatEnum } from './types';
|
|
14
|
+
|
|
15
|
+
// TODO(burdon): Consider factoring out to separate `@dxos/json-schema`
|
|
16
|
+
// TODO(burdon): Media encoding.
|
|
17
|
+
// - https://json-schema.org/understanding-json-schema/reference/non_json_data
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Formats.
|
|
21
|
+
* https://json-schema.org/understanding-json-schema/reference/string#built-in-formats
|
|
22
|
+
* NOTE: A JSON Schema validator will ignore any format type that it does not understand.
|
|
23
|
+
*/
|
|
24
|
+
// TODO(burdon): Add fields for `examples`, `message`, etc.
|
|
25
|
+
export namespace Format {
|
|
26
|
+
export import TypeFormat = TypeFormatEnum;
|
|
27
|
+
|
|
28
|
+
// Strings
|
|
29
|
+
export const DXN = Keys.DXN.Schema;
|
|
30
|
+
export const Email = StringUtil.Email;
|
|
31
|
+
export const Formula = StringUtil.Formula;
|
|
32
|
+
export const Hostname = StringUtil.Hostname;
|
|
33
|
+
export const JSON = StringUtil.JSON;
|
|
34
|
+
export const Markdown = StringUtil.Markdown;
|
|
35
|
+
export const Regex = StringUtil.Regex;
|
|
36
|
+
export const URL = StringUtil.URL;
|
|
37
|
+
export const UUID = Schema.UUID;
|
|
38
|
+
|
|
39
|
+
// Numbers
|
|
40
|
+
// TODO(burdon): BigInt.
|
|
41
|
+
export const Currency = NumberUtil.Currency;
|
|
42
|
+
export const Integer = NumberUtil.Integer;
|
|
43
|
+
export const Percent = NumberUtil.Percent;
|
|
44
|
+
export const Timestamp = NumberUtil.Timestamp;
|
|
45
|
+
|
|
46
|
+
// Dates and times
|
|
47
|
+
export const DateTime = DateUtil.DateTime;
|
|
48
|
+
export const Date = DateUtil.DateOnly;
|
|
49
|
+
export const Time = DateUtil.TimeOnly;
|
|
50
|
+
export const Duration = DateUtil.Duration;
|
|
51
|
+
|
|
52
|
+
// Objects
|
|
53
|
+
export const GeoPoint = ObjectUtil.GeoPoint;
|
|
54
|
+
export type GeoPoint = ObjectUtil.GeoPoint;
|
|
55
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
export type { SimpleDate, SimpleDateTime, SimpleTime } from './date';
|
|
6
|
+
export { CurrencyAnnotationId, DecimalPrecision, Currency } from './number';
|
|
7
|
+
export { GeoPoint, GeoLocation } from './object';
|
|
8
|
+
|
|
9
|
+
export * from './format';
|
|
10
|
+
export * from './select';
|
|
11
|
+
export * from './string';
|
|
12
|
+
export * from './types';
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
|
|
7
|
+
import { FormatAnnotation, TypeFormat } from './types';
|
|
8
|
+
|
|
9
|
+
const encodeMultipleOf = (divisor: number) => 1 / Math.pow(10, divisor);
|
|
10
|
+
|
|
11
|
+
const encodeMultiple =
|
|
12
|
+
<A extends number>(divisor?: number) =>
|
|
13
|
+
<I, R>(self: Schema.Schema<A, I, R>) =>
|
|
14
|
+
divisor === undefined || divisor === 0 ? self : self.pipe(Schema.multipleOf(encodeMultipleOf(divisor)));
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Convert number of digits to multipleOf annotation.
|
|
18
|
+
*/
|
|
19
|
+
export const DecimalPrecision = Schema.transform(Schema.Number, Schema.Number, {
|
|
20
|
+
strict: true,
|
|
21
|
+
encode: (value) => encodeMultipleOf(value),
|
|
22
|
+
decode: (value) => Math.log10(1 / value),
|
|
23
|
+
}).annotations({
|
|
24
|
+
title: 'Number of digits',
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
export const CurrencyAnnotationId = Symbol.for('@dxos/schema/annotation/Currency');
|
|
28
|
+
|
|
29
|
+
export type CurrencyAnnotation = {
|
|
30
|
+
decimals?: number;
|
|
31
|
+
code?: string;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* ISO 4217 currency code.
|
|
36
|
+
*/
|
|
37
|
+
export const Currency = ({ decimals, code }: CurrencyAnnotation = { decimals: 2 }) =>
|
|
38
|
+
Schema.Number.pipe(
|
|
39
|
+
encodeMultiple(decimals),
|
|
40
|
+
FormatAnnotation.set(TypeFormat.Currency),
|
|
41
|
+
Schema.annotations({
|
|
42
|
+
title: 'Currency',
|
|
43
|
+
description: 'Currency value',
|
|
44
|
+
...(code ? { [CurrencyAnnotationId]: code.toUpperCase() } : {}),
|
|
45
|
+
}),
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
export type PercentAnnotation = {
|
|
49
|
+
decimals?: number;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Integer.
|
|
54
|
+
*/
|
|
55
|
+
export const Integer = () =>
|
|
56
|
+
Schema.Number.pipe(
|
|
57
|
+
Schema.int(),
|
|
58
|
+
FormatAnnotation.set(TypeFormat.Integer),
|
|
59
|
+
Schema.annotations({
|
|
60
|
+
title: 'Integer',
|
|
61
|
+
description: 'Integer value',
|
|
62
|
+
}),
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Percent.
|
|
67
|
+
*/
|
|
68
|
+
// TODO(burdon): Define min/max (e.g., 0, 1).
|
|
69
|
+
export const Percent = ({ decimals }: PercentAnnotation = { decimals: 2 }) =>
|
|
70
|
+
Schema.Number.pipe(
|
|
71
|
+
encodeMultiple(decimals),
|
|
72
|
+
FormatAnnotation.set(TypeFormat.Percent),
|
|
73
|
+
Schema.annotations({
|
|
74
|
+
title: 'Percent',
|
|
75
|
+
description: 'Percentage value',
|
|
76
|
+
}),
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Unix timestamp.
|
|
81
|
+
* https://en.wikipedia.org/wiki/Unix_time
|
|
82
|
+
*/
|
|
83
|
+
export const Timestamp = Schema.Number.pipe(
|
|
84
|
+
FormatAnnotation.set(TypeFormat.Timestamp),
|
|
85
|
+
Schema.annotations({
|
|
86
|
+
title: 'Timestamp',
|
|
87
|
+
description: 'Unix timestamp',
|
|
88
|
+
}),
|
|
89
|
+
);
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
|
|
7
|
+
import { clamp } from '@dxos/util';
|
|
8
|
+
|
|
9
|
+
import { FormatAnnotation, TypeFormat } from './types';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* GeoJSON Format
|
|
13
|
+
* https://datatracker.ietf.org/doc/html/rfc7946
|
|
14
|
+
* https://datatracker.ietf.org/doc/html/rfc7946#section-3.1.1
|
|
15
|
+
* https://en.wikipedia.org/wiki/Geographic_coordinate_system
|
|
16
|
+
* https://geojson.org
|
|
17
|
+
* {
|
|
18
|
+
* "type": "Point",
|
|
19
|
+
* "coordinates": [0, 51.47] // [longitude, latitude]
|
|
20
|
+
* }
|
|
21
|
+
* Note: optional third element for altitude.
|
|
22
|
+
*/
|
|
23
|
+
export const GeoPoint = Schema.Tuple(
|
|
24
|
+
Schema.Number.pipe(Schema.annotations({ title: 'Longitude' }), Schema.clamp(-180, 180), Schema.multipleOf(0.00001)),
|
|
25
|
+
Schema.Number.pipe(Schema.annotations({ title: 'Latitude' }), Schema.clamp(-90, 90), Schema.multipleOf(0.00001)),
|
|
26
|
+
Schema.optionalElement(Schema.Number).annotations({
|
|
27
|
+
title: 'Height ASL (m)',
|
|
28
|
+
}),
|
|
29
|
+
).pipe(
|
|
30
|
+
FormatAnnotation.set(TypeFormat.GeoPoint),
|
|
31
|
+
Schema.annotations({
|
|
32
|
+
title: 'GeoPoint',
|
|
33
|
+
description: 'GeoJSON Position',
|
|
34
|
+
}),
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
export type GeoPoint = Schema.Schema.Type<typeof GeoPoint>;
|
|
38
|
+
|
|
39
|
+
export type GeoLocation = {
|
|
40
|
+
longitude: number;
|
|
41
|
+
latitude: number;
|
|
42
|
+
height?: number;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Geolocation utilities for working with GeoPoint format.
|
|
47
|
+
*/
|
|
48
|
+
export namespace GeoLocation {
|
|
49
|
+
/**
|
|
50
|
+
* Convert latitude and longitude to GeoPoint (GeoJSON format [longitude, latitude, height?]).
|
|
51
|
+
* Clamps values to valid ranges: latitude [-90, 90], longitude [-180, 180].
|
|
52
|
+
*/
|
|
53
|
+
export const toGeoPoint = ({ longitude, latitude, height }: GeoLocation): GeoPoint => {
|
|
54
|
+
// TODO(ZaymonFC): Use schema validation instead of doing this manually.
|
|
55
|
+
const clampedLongitude = clamp(longitude, -180, 180);
|
|
56
|
+
const clampedLatitude = clamp(latitude, -90, 90);
|
|
57
|
+
return height !== undefined ? [clampedLongitude, clampedLatitude, height] : [clampedLongitude, clampedLatitude];
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Extract latitude and longitude from GeoPoint (GeoJSON format [longitude, latitude, height?]).
|
|
62
|
+
*/
|
|
63
|
+
export const fromGeoPoint = (geoPoint: GeoPoint | undefined): GeoLocation => {
|
|
64
|
+
if (!geoPoint) {
|
|
65
|
+
return { longitude: 0, latitude: 0 };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const result: GeoLocation = {
|
|
69
|
+
longitude: geoPoint[0],
|
|
70
|
+
latitude: geoPoint[1],
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// Add height if defined.
|
|
74
|
+
if (geoPoint[2] !== undefined) {
|
|
75
|
+
result.height = geoPoint[2];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return result;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
|
|
7
|
+
/** Schema for a single select option. Used to define choices in a {single|multi}-select field. */
|
|
8
|
+
export const SelectOptionSchema = Schema.Struct({
|
|
9
|
+
/** Stable identifier for the option. */
|
|
10
|
+
id: Schema.NonEmptyString,
|
|
11
|
+
title: Schema.String,
|
|
12
|
+
/** Color palette used for visual styling. */
|
|
13
|
+
color: Schema.String,
|
|
14
|
+
}).pipe(Schema.mutable);
|
|
15
|
+
|
|
16
|
+
export type SelectOption = Schema.Schema.Type<typeof SelectOptionSchema>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
7
|
+
|
|
8
|
+
import { FormatAnnotation, TypeFormat } from './types';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Email address (RFC 5321)
|
|
12
|
+
* https://datatracker.ietf.org/doc/html/rfc5321#section-4.1.2
|
|
13
|
+
*/
|
|
14
|
+
export const Email = Schema.String.pipe(
|
|
15
|
+
Schema.pattern(/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/),
|
|
16
|
+
FormatAnnotation.set(TypeFormat.Email),
|
|
17
|
+
Schema.annotations({
|
|
18
|
+
title: 'Email',
|
|
19
|
+
description: 'Email address',
|
|
20
|
+
}),
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
*/
|
|
26
|
+
// TODO(burdon): Implement.
|
|
27
|
+
export const Formula = Schema.String.pipe(FormatAnnotation.set(TypeFormat.Formula));
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
*/
|
|
32
|
+
// TODO(burdon): Implement.
|
|
33
|
+
export const Hostname = Schema.String.pipe(FormatAnnotation.set(TypeFormat.Hostname));
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
*
|
|
37
|
+
*/
|
|
38
|
+
// TODO(burdon): Implement.
|
|
39
|
+
export const JSON = Schema.String.pipe(FormatAnnotation.set(TypeFormat.JSON));
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
*
|
|
43
|
+
*/
|
|
44
|
+
// TODO(burdon): Implement.
|
|
45
|
+
export const Markdown = Schema.String.pipe(FormatAnnotation.set(TypeFormat.Markdown));
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Regex
|
|
49
|
+
* https://json-schema.org/understanding-json-schema/reference/regular_expressions
|
|
50
|
+
* https://ecma-international.org/publications-and-standards/standards/ecma-262
|
|
51
|
+
*/
|
|
52
|
+
// TODO(burdon): Implement.
|
|
53
|
+
export const Regex = Schema.String.pipe(FormatAnnotation.set(TypeFormat.Regex));
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* https://datatracker.ietf.org/doc/html/rfc3986#section-1.1.3
|
|
57
|
+
*/
|
|
58
|
+
export const URL = Schema.String.pipe(
|
|
59
|
+
Schema.pattern(/^(\w+?:\/\/)?([\da-z.-]+)\.([a-z.]{2,6})([/\w .-]*)*\/?$/i),
|
|
60
|
+
FormatAnnotation.set(TypeFormat.URL),
|
|
61
|
+
Schema.annotations({
|
|
62
|
+
title: 'URL',
|
|
63
|
+
description: 'URL',
|
|
64
|
+
}),
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* UUID (RFC 4122)
|
|
69
|
+
* https://datatracker.ietf.org/doc/html/rfc4122
|
|
70
|
+
*/
|
|
71
|
+
export const UUID = Schema.UUID.pipe(
|
|
72
|
+
FormatAnnotation.set(TypeFormat.UUID),
|
|
73
|
+
Schema.annotations({
|
|
74
|
+
[SchemaAST.ExamplesAnnotationId]: ['3e4666bf-d5e5-4aa7-b8ce-cefe41c7568a'],
|
|
75
|
+
}),
|
|
76
|
+
);
|