@dxos/echo 0.8.1-staging.31c3ee1
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/LICENSE +8 -0
- package/README.md +21 -0
- package/dist/lib/browser/index.mjs +49 -0
- package/dist/lib/browser/index.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -0
- package/dist/lib/node/index.cjs +66 -0
- package/dist/lib/node/index.cjs.map +7 -0
- package/dist/lib/node/meta.json +1 -0
- package/dist/lib/node-esm/index.mjs +49 -0
- package/dist/lib/node-esm/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -0
- package/dist/types/src/Database.d.ts +8 -0
- package/dist/types/src/Database.d.ts.map +1 -0
- package/dist/types/src/Queue.d.ts +8 -0
- package/dist/types/src/Queue.d.ts.map +1 -0
- package/dist/types/src/Space.d.ts +8 -0
- package/dist/types/src/Space.d.ts.map +1 -0
- package/dist/types/src/Type.d.ts +49 -0
- package/dist/types/src/Type.d.ts.map +1 -0
- package/dist/types/src/api.test.d.ts +2 -0
- package/dist/types/src/api.test.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +7 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +43 -0
- package/src/Database.ts +11 -0
- package/src/Queue.ts +11 -0
- package/src/Space.ts +11 -0
- package/src/Type.ts +99 -0
- package/src/api.test.ts +94 -0
- package/src/index.ts +12 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
Copyright (c) 2022 DXOS
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
5
|
+
|
|
6
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# @dxos/echo
|
|
2
|
+
|
|
3
|
+
ECHO API.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm i @dxos/echo
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## DXOS Resources
|
|
12
|
+
|
|
13
|
+
- [Website](https://dxos.org)
|
|
14
|
+
- [Developer Documentation](https://docs.dxos.org)
|
|
15
|
+
- Talk to us on [Discord](https://dxos.org/discord)
|
|
16
|
+
|
|
17
|
+
## Contributions
|
|
18
|
+
|
|
19
|
+
Your ideas, issues, and code are most welcome. Please take a look at our [community code of conduct](https://github.com/dxos/dxos/blob/main/CODE_OF_CONDUCT.md), the [issue guide](https://github.com/dxos/dxos/blob/main/CONTRIBUTING.md#submitting-issues), and the [PR contribution guide](https://github.com/dxos/dxos/blob/main/CONTRIBUTING.md#submitting-prs).
|
|
20
|
+
|
|
21
|
+
License: [MIT](./LICENSE) Copyright 2022 © DXOS
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import "@dxos/node-std/globals";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __export = (target, all) => {
|
|
4
|
+
for (var name in all)
|
|
5
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
// packages/core/echo/echo/src/index.ts
|
|
9
|
+
import { DXN } from "@dxos/keys";
|
|
10
|
+
|
|
11
|
+
// packages/core/echo/echo/src/Database.ts
|
|
12
|
+
var Database_exports = {};
|
|
13
|
+
|
|
14
|
+
// packages/core/echo/echo/src/Queue.ts
|
|
15
|
+
var Queue_exports = {};
|
|
16
|
+
|
|
17
|
+
// packages/core/echo/echo/src/Space.ts
|
|
18
|
+
var Space_exports = {};
|
|
19
|
+
|
|
20
|
+
// packages/core/echo/echo/src/Type.ts
|
|
21
|
+
var Type_exports = {};
|
|
22
|
+
__export(Type_exports, {
|
|
23
|
+
Kind: () => EntityKind,
|
|
24
|
+
ObjectId: () => ObjectId,
|
|
25
|
+
Ref: () => Ref,
|
|
26
|
+
create: () => create,
|
|
27
|
+
def: () => def,
|
|
28
|
+
getDXN: () => getSchemaDXN,
|
|
29
|
+
getMeta: () => getTypeAnnotation,
|
|
30
|
+
getSchema: () => getSchema,
|
|
31
|
+
getTypename: () => getSchemaTypename,
|
|
32
|
+
getVersion: () => getSchemaVersion,
|
|
33
|
+
instanceOf: () => isInstanceOf,
|
|
34
|
+
ref: () => ref
|
|
35
|
+
});
|
|
36
|
+
import { EchoObject, EntityKind, ObjectId, Ref as Ref$, getTypeAnnotation, getSchema, getSchemaDXN, getSchemaTypename, getSchemaVersion, isInstanceOf } from "@dxos/echo-schema";
|
|
37
|
+
import { create as create$, makeRef } from "@dxos/live-object";
|
|
38
|
+
var ref = makeRef;
|
|
39
|
+
var create = create$;
|
|
40
|
+
var def = (meta) => EchoObject(meta);
|
|
41
|
+
var Ref = (self) => Ref$(self);
|
|
42
|
+
export {
|
|
43
|
+
DXN,
|
|
44
|
+
Database_exports as Database,
|
|
45
|
+
Queue_exports as Queue,
|
|
46
|
+
Space_exports as Space,
|
|
47
|
+
Type_exports as Type
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/index.ts", "../../../src/Database.ts", "../../../src/Queue.ts", "../../../src/Space.ts", "../../../src/Type.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { DXN } from '@dxos/keys';\n\nexport { DXN };\n\nexport * as Database from './Database';\nexport * as Queue from './Queue';\nexport * as Space from './Space';\nexport * as Type from './Type';\n", "//\n// Copyright 2025 DXOS.org\n//\n\n/**\n * Database API.\n *\n * @category api namespace\n * @since 0.9.0\n */\nexport declare namespace Database {}\n", "//\n// Copyright 2025 DXOS.org\n//\n\n/**\n * Queue API.\n *\n * @category api namespace\n * @since 0.9.0\n */\nexport declare namespace Queue {}\n", "//\n// Copyright 2025 DXOS.org\n//\n\n/**\n * Space API.\n *\n * @category api namespace\n * @since 0.9.0\n */\nexport declare namespace Space {}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { type Schema } from 'effect';\n\nimport {\n type BaseSchema,\n type EchoSchema,\n type Expando as Expando$,\n type ImmutableSchema,\n type JsonSchemaType,\n type TypeMeta,\n EchoObject,\n EntityKind,\n ObjectId,\n Ref as Ref$,\n getTypeAnnotation,\n getSchema,\n getSchemaDXN,\n getSchemaTypename,\n getSchemaVersion,\n isInstanceOf,\n} from '@dxos/echo-schema';\nimport { create as create$, makeRef } from '@dxos/live-object';\n\n// NOTES:\n// - New Echo package and namespaces allow for incremental migration; vastly simplifies imports.\n// - Split into separate ECHO namespaces: Database, Space, Type, Query, Queue.\n// - Example; import { Database, Type, Query, Queue } from '@dxos/echo';\n// - Use `declare namespace` for types (no code is generated). See Effect pattern, where Schema is a namespace, interface, and function.\n// - Test with @dxos/schema/testing types.\n// - Define user (Composer) types in namespace (e.g., of plugin) and drop Type suffix; remove all deprecated Braneframe types.\n\nexport type { TypeMeta as Meta, JsonSchemaType as JsonSchema };\nexport {\n EntityKind as Kind,\n ObjectId,\n getTypeAnnotation as getMeta,\n getSchema,\n getSchemaDXN as getDXN,\n getSchemaTypename as getTypename,\n getSchemaVersion as getVersion,\n isInstanceOf as instanceOf,\n};\n\n/**\n * Type API.\n *\n * @category api namespace\n * @since 0.9.0\n */\nexport declare namespace Type {\n /**\n * A schema that can be extended with arbitrary properties.\n */\n export type Expando = Expando$;\n\n export type Abstract<T = any> = BaseSchema<T>;\n export type ImmutableType<T> = ImmutableSchema<T>;\n export type MutableType<T> = EchoSchema<T>;\n}\n\n//\n// Constructors\n//\n\nexport const ref = makeRef;\nexport const create = create$;\n\n//\n// Combinators\n//\n\n/**\n * Defines an ECHO type.\n *\n * @example\n * ```ts\n * const Org = S.Struct({\n * name: S.String,\n * }).pipe(Type.def({ typename: 'example.com/type/Org', version: '1.0.0' }));\n * ```\n */\nexport const def = (meta: TypeMeta) => EchoObject(meta);\n\n/**\n * Defines a reference to an ECHO object.\n *\n * @example\n * ```ts\n * import { Type } from '@dxos/echo';\n * const Contact = S.Struct({\n * name: S.String,\n * employer: Type.Ref(Org),\n * }).pipe(Type.def({ typename: 'example.com/type/Contact', version: '1.0.0' }));\n * ```\n */\nexport const Ref = <S extends Schema.Schema.AnyNoContext>(self: S) => Ref$<Schema.Schema.Type<S>>(self);\n"],
|
|
5
|
+
"mappings": ";;;;;;;;AAIA,SAASA,WAAW;;;ACJpB;;;ACAA;;;ACAA;;;ACAA;;;;;;;;;;;;;;;AAMA,SAOEC,YACAC,YACAC,UACAC,OAAOC,MACPC,mBACAC,WACAC,cACAC,mBACAC,kBACAC,oBACK;AACP,SAASC,UAAUC,SAASC,eAAe;AA2CpC,IAAMC,MAAMC;AACZ,IAAMC,SAASC;AAgBf,IAAMC,MAAM,CAACC,SAAmBC,WAAWD,IAAAA;AAc3C,IAAME,MAAM,CAAuCC,SAAYC,KAA4BD,IAAAA;",
|
|
6
|
+
"names": ["DXN", "EchoObject", "EntityKind", "ObjectId", "Ref", "Ref$", "getTypeAnnotation", "getSchema", "getSchemaDXN", "getSchemaTypename", "getSchemaVersion", "isInstanceOf", "create", "create$", "makeRef", "ref", "makeRef", "create", "create$", "def", "meta", "EchoObject", "Ref", "self", "Ref$"]
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"inputs":{"packages/core/echo/echo/src/Database.ts":{"bytes":689,"imports":[],"format":"esm"},"packages/core/echo/echo/src/Queue.ts":{"bytes":671,"imports":[],"format":"esm"},"packages/core/echo/echo/src/Space.ts":{"bytes":671,"imports":[],"format":"esm"},"packages/core/echo/echo/src/Type.ts":{"bytes":6001,"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo/src/index.ts":{"bytes":1157,"imports":[{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"packages/core/echo/echo/src/Database.ts","kind":"import-statement","original":"./Database"},{"path":"packages/core/echo/echo/src/Queue.ts","kind":"import-statement","original":"./Queue"},{"path":"packages/core/echo/echo/src/Space.ts","kind":"import-statement","original":"./Space"},{"path":"packages/core/echo/echo/src/Type.ts","kind":"import-statement","original":"./Type"}],"format":"esm"}},"outputs":{"packages/core/echo/echo/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":4021},"packages/core/echo/echo/dist/lib/browser/index.mjs":{"imports":[{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true}],"exports":["DXN","Database","Queue","Space","Type"],"entryPoint":"packages/core/echo/echo/src/index.ts","inputs":{"packages/core/echo/echo/src/index.ts":{"bytesInOutput":34},"packages/core/echo/echo/src/Database.ts":{"bytesInOutput":27},"packages/core/echo/echo/src/Queue.ts":{"bytesInOutput":24},"packages/core/echo/echo/src/Space.ts":{"bytesInOutput":24},"packages/core/echo/echo/src/Type.ts":{"bytesInOutput":744}},"bytes":1421}}}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var node_exports = {};
|
|
20
|
+
__export(node_exports, {
|
|
21
|
+
DXN: () => import_keys.DXN,
|
|
22
|
+
Database: () => Database_exports,
|
|
23
|
+
Queue: () => Queue_exports,
|
|
24
|
+
Space: () => Space_exports,
|
|
25
|
+
Type: () => Type_exports
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(node_exports);
|
|
28
|
+
var import_keys = require("@dxos/keys");
|
|
29
|
+
var import_echo_schema = require("@dxos/echo-schema");
|
|
30
|
+
var import_live_object = require("@dxos/live-object");
|
|
31
|
+
var __defProp2 = Object.defineProperty;
|
|
32
|
+
var __export2 = (target, all) => {
|
|
33
|
+
for (var name in all)
|
|
34
|
+
__defProp2(target, name, { get: all[name], enumerable: true });
|
|
35
|
+
};
|
|
36
|
+
var Database_exports = {};
|
|
37
|
+
var Queue_exports = {};
|
|
38
|
+
var Space_exports = {};
|
|
39
|
+
var Type_exports = {};
|
|
40
|
+
__export2(Type_exports, {
|
|
41
|
+
Kind: () => import_echo_schema.EntityKind,
|
|
42
|
+
ObjectId: () => import_echo_schema.ObjectId,
|
|
43
|
+
Ref: () => Ref,
|
|
44
|
+
create: () => create,
|
|
45
|
+
def: () => def,
|
|
46
|
+
getDXN: () => import_echo_schema.getSchemaDXN,
|
|
47
|
+
getMeta: () => import_echo_schema.getTypeAnnotation,
|
|
48
|
+
getSchema: () => import_echo_schema.getSchema,
|
|
49
|
+
getTypename: () => import_echo_schema.getSchemaTypename,
|
|
50
|
+
getVersion: () => import_echo_schema.getSchemaVersion,
|
|
51
|
+
instanceOf: () => import_echo_schema.isInstanceOf,
|
|
52
|
+
ref: () => ref
|
|
53
|
+
});
|
|
54
|
+
var ref = import_live_object.makeRef;
|
|
55
|
+
var create = import_live_object.create;
|
|
56
|
+
var def = (meta) => (0, import_echo_schema.EchoObject)(meta);
|
|
57
|
+
var Ref = (self) => (0, import_echo_schema.Ref)(self);
|
|
58
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
59
|
+
0 && (module.exports = {
|
|
60
|
+
DXN,
|
|
61
|
+
Database,
|
|
62
|
+
Queue,
|
|
63
|
+
Space,
|
|
64
|
+
Type
|
|
65
|
+
});
|
|
66
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/index.ts", "../../../src/Database.ts", "../../../src/Queue.ts", "../../../src/Space.ts", "../../../src/Type.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { DXN } from '@dxos/keys';\n\nexport { DXN };\n\nexport * as Database from './Database';\nexport * as Queue from './Queue';\nexport * as Space from './Space';\nexport * as Type from './Type';\n", "//\n// Copyright 2025 DXOS.org\n//\n\n/**\n * Database API.\n *\n * @category api namespace\n * @since 0.9.0\n */\nexport declare namespace Database {}\n", "//\n// Copyright 2025 DXOS.org\n//\n\n/**\n * Queue API.\n *\n * @category api namespace\n * @since 0.9.0\n */\nexport declare namespace Queue {}\n", "//\n// Copyright 2025 DXOS.org\n//\n\n/**\n * Space API.\n *\n * @category api namespace\n * @since 0.9.0\n */\nexport declare namespace Space {}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { type Schema } from 'effect';\n\nimport {\n type BaseSchema,\n type EchoSchema,\n type Expando as Expando$,\n type ImmutableSchema,\n type JsonSchemaType,\n type TypeMeta,\n EchoObject,\n EntityKind,\n ObjectId,\n Ref as Ref$,\n getTypeAnnotation,\n getSchema,\n getSchemaDXN,\n getSchemaTypename,\n getSchemaVersion,\n isInstanceOf,\n} from '@dxos/echo-schema';\nimport { create as create$, makeRef } from '@dxos/live-object';\n\n// NOTES:\n// - New Echo package and namespaces allow for incremental migration; vastly simplifies imports.\n// - Split into separate ECHO namespaces: Database, Space, Type, Query, Queue.\n// - Example; import { Database, Type, Query, Queue } from '@dxos/echo';\n// - Use `declare namespace` for types (no code is generated). See Effect pattern, where Schema is a namespace, interface, and function.\n// - Test with @dxos/schema/testing types.\n// - Define user (Composer) types in namespace (e.g., of plugin) and drop Type suffix; remove all deprecated Braneframe types.\n\nexport type { TypeMeta as Meta, JsonSchemaType as JsonSchema };\nexport {\n EntityKind as Kind,\n ObjectId,\n getTypeAnnotation as getMeta,\n getSchema,\n getSchemaDXN as getDXN,\n getSchemaTypename as getTypename,\n getSchemaVersion as getVersion,\n isInstanceOf as instanceOf,\n};\n\n/**\n * Type API.\n *\n * @category api namespace\n * @since 0.9.0\n */\nexport declare namespace Type {\n /**\n * A schema that can be extended with arbitrary properties.\n */\n export type Expando = Expando$;\n\n export type Abstract<T = any> = BaseSchema<T>;\n export type ImmutableType<T> = ImmutableSchema<T>;\n export type MutableType<T> = EchoSchema<T>;\n}\n\n//\n// Constructors\n//\n\nexport const ref = makeRef;\nexport const create = create$;\n\n//\n// Combinators\n//\n\n/**\n * Defines an ECHO type.\n *\n * @example\n * ```ts\n * const Org = S.Struct({\n * name: S.String,\n * }).pipe(Type.def({ typename: 'example.com/type/Org', version: '1.0.0' }));\n * ```\n */\nexport const def = (meta: TypeMeta) => EchoObject(meta);\n\n/**\n * Defines a reference to an ECHO object.\n *\n * @example\n * ```ts\n * import { Type } from '@dxos/echo';\n * const Contact = S.Struct({\n * name: S.String,\n * employer: Type.Ref(Org),\n * }).pipe(Type.def({ typename: 'example.com/type/Contact', version: '1.0.0' }));\n * ```\n */\nexport const Ref = <S extends Schema.Schema.AnyNoContext>(self: S) => Ref$<Schema.Schema.Type<S>>(self);\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,kBAAoB;AIEpB,yBAiBO;AACP,yBAA2C;;;;;;AHxB3C,IAAA,mBAAA,CAAA;ACAA,IAAA,gBAAA,CAAA;ACAA,IAAA,gBAAA,CAAA;ACAA,IAAA,eAAA,CAAA;;;;;;;;;;;;;;;AAmEO,IAAMA,MAAMC;AACZ,IAAMC,SAASC,mBAAAA;AAgBf,IAAMC,MAAM,CAACC,aAAmBC,+BAAWD,IAAAA;AAc3C,IAAME,MAAM,CAAuCC,aAAYC,mBAAAA,KAA4BD,IAAAA;",
|
|
6
|
+
"names": ["ref", "makeRef", "create", "create$", "def", "meta", "EchoObject", "Ref", "self", "Ref$"]
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"inputs":{"packages/core/echo/echo/src/Database.ts":{"bytes":689,"imports":[],"format":"esm"},"packages/core/echo/echo/src/Queue.ts":{"bytes":671,"imports":[],"format":"esm"},"packages/core/echo/echo/src/Space.ts":{"bytes":671,"imports":[],"format":"esm"},"packages/core/echo/echo/src/Type.ts":{"bytes":6001,"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo/src/index.ts":{"bytes":1157,"imports":[{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"packages/core/echo/echo/src/Database.ts","kind":"import-statement","original":"./Database"},{"path":"packages/core/echo/echo/src/Queue.ts","kind":"import-statement","original":"./Queue"},{"path":"packages/core/echo/echo/src/Space.ts","kind":"import-statement","original":"./Space"},{"path":"packages/core/echo/echo/src/Type.ts","kind":"import-statement","original":"./Type"}],"format":"esm"}},"outputs":{"packages/core/echo/echo/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":4020},"packages/core/echo/echo/dist/lib/node/index.cjs":{"imports":[{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true}],"exports":["DXN","Database","Queue","Space","Type"],"entryPoint":"packages/core/echo/echo/src/index.ts","inputs":{"packages/core/echo/echo/src/index.ts":{"bytesInOutput":34},"packages/core/echo/echo/src/Database.ts":{"bytesInOutput":27},"packages/core/echo/echo/src/Queue.ts":{"bytesInOutput":24},"packages/core/echo/echo/src/Space.ts":{"bytesInOutput":24},"packages/core/echo/echo/src/Type.ts":{"bytesInOutput":744}},"bytes":1388}}}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __export = (target, all) => {
|
|
4
|
+
for (var name in all)
|
|
5
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
// packages/core/echo/echo/src/index.ts
|
|
9
|
+
import { DXN } from "@dxos/keys";
|
|
10
|
+
|
|
11
|
+
// packages/core/echo/echo/src/Database.ts
|
|
12
|
+
var Database_exports = {};
|
|
13
|
+
|
|
14
|
+
// packages/core/echo/echo/src/Queue.ts
|
|
15
|
+
var Queue_exports = {};
|
|
16
|
+
|
|
17
|
+
// packages/core/echo/echo/src/Space.ts
|
|
18
|
+
var Space_exports = {};
|
|
19
|
+
|
|
20
|
+
// packages/core/echo/echo/src/Type.ts
|
|
21
|
+
var Type_exports = {};
|
|
22
|
+
__export(Type_exports, {
|
|
23
|
+
Kind: () => EntityKind,
|
|
24
|
+
ObjectId: () => ObjectId,
|
|
25
|
+
Ref: () => Ref,
|
|
26
|
+
create: () => create,
|
|
27
|
+
def: () => def,
|
|
28
|
+
getDXN: () => getSchemaDXN,
|
|
29
|
+
getMeta: () => getTypeAnnotation,
|
|
30
|
+
getSchema: () => getSchema,
|
|
31
|
+
getTypename: () => getSchemaTypename,
|
|
32
|
+
getVersion: () => getSchemaVersion,
|
|
33
|
+
instanceOf: () => isInstanceOf,
|
|
34
|
+
ref: () => ref
|
|
35
|
+
});
|
|
36
|
+
import { EchoObject, EntityKind, ObjectId, Ref as Ref$, getTypeAnnotation, getSchema, getSchemaDXN, getSchemaTypename, getSchemaVersion, isInstanceOf } from "@dxos/echo-schema";
|
|
37
|
+
import { create as create$, makeRef } from "@dxos/live-object";
|
|
38
|
+
var ref = makeRef;
|
|
39
|
+
var create = create$;
|
|
40
|
+
var def = (meta) => EchoObject(meta);
|
|
41
|
+
var Ref = (self) => Ref$(self);
|
|
42
|
+
export {
|
|
43
|
+
DXN,
|
|
44
|
+
Database_exports as Database,
|
|
45
|
+
Queue_exports as Queue,
|
|
46
|
+
Space_exports as Space,
|
|
47
|
+
Type_exports as Type
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/index.ts", "../../../src/Database.ts", "../../../src/Queue.ts", "../../../src/Space.ts", "../../../src/Type.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { DXN } from '@dxos/keys';\n\nexport { DXN };\n\nexport * as Database from './Database';\nexport * as Queue from './Queue';\nexport * as Space from './Space';\nexport * as Type from './Type';\n", "//\n// Copyright 2025 DXOS.org\n//\n\n/**\n * Database API.\n *\n * @category api namespace\n * @since 0.9.0\n */\nexport declare namespace Database {}\n", "//\n// Copyright 2025 DXOS.org\n//\n\n/**\n * Queue API.\n *\n * @category api namespace\n * @since 0.9.0\n */\nexport declare namespace Queue {}\n", "//\n// Copyright 2025 DXOS.org\n//\n\n/**\n * Space API.\n *\n * @category api namespace\n * @since 0.9.0\n */\nexport declare namespace Space {}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { type Schema } from 'effect';\n\nimport {\n type BaseSchema,\n type EchoSchema,\n type Expando as Expando$,\n type ImmutableSchema,\n type JsonSchemaType,\n type TypeMeta,\n EchoObject,\n EntityKind,\n ObjectId,\n Ref as Ref$,\n getTypeAnnotation,\n getSchema,\n getSchemaDXN,\n getSchemaTypename,\n getSchemaVersion,\n isInstanceOf,\n} from '@dxos/echo-schema';\nimport { create as create$, makeRef } from '@dxos/live-object';\n\n// NOTES:\n// - New Echo package and namespaces allow for incremental migration; vastly simplifies imports.\n// - Split into separate ECHO namespaces: Database, Space, Type, Query, Queue.\n// - Example; import { Database, Type, Query, Queue } from '@dxos/echo';\n// - Use `declare namespace` for types (no code is generated). See Effect pattern, where Schema is a namespace, interface, and function.\n// - Test with @dxos/schema/testing types.\n// - Define user (Composer) types in namespace (e.g., of plugin) and drop Type suffix; remove all deprecated Braneframe types.\n\nexport type { TypeMeta as Meta, JsonSchemaType as JsonSchema };\nexport {\n EntityKind as Kind,\n ObjectId,\n getTypeAnnotation as getMeta,\n getSchema,\n getSchemaDXN as getDXN,\n getSchemaTypename as getTypename,\n getSchemaVersion as getVersion,\n isInstanceOf as instanceOf,\n};\n\n/**\n * Type API.\n *\n * @category api namespace\n * @since 0.9.0\n */\nexport declare namespace Type {\n /**\n * A schema that can be extended with arbitrary properties.\n */\n export type Expando = Expando$;\n\n export type Abstract<T = any> = BaseSchema<T>;\n export type ImmutableType<T> = ImmutableSchema<T>;\n export type MutableType<T> = EchoSchema<T>;\n}\n\n//\n// Constructors\n//\n\nexport const ref = makeRef;\nexport const create = create$;\n\n//\n// Combinators\n//\n\n/**\n * Defines an ECHO type.\n *\n * @example\n * ```ts\n * const Org = S.Struct({\n * name: S.String,\n * }).pipe(Type.def({ typename: 'example.com/type/Org', version: '1.0.0' }));\n * ```\n */\nexport const def = (meta: TypeMeta) => EchoObject(meta);\n\n/**\n * Defines a reference to an ECHO object.\n *\n * @example\n * ```ts\n * import { Type } from '@dxos/echo';\n * const Contact = S.Struct({\n * name: S.String,\n * employer: Type.Ref(Org),\n * }).pipe(Type.def({ typename: 'example.com/type/Contact', version: '1.0.0' }));\n * ```\n */\nexport const Ref = <S extends Schema.Schema.AnyNoContext>(self: S) => Ref$<Schema.Schema.Type<S>>(self);\n"],
|
|
5
|
+
"mappings": ";;;;;;;;AAIA,SAASA,WAAW;;;ACJpB;;;ACAA;;;ACAA;;;ACAA;;;;;;;;;;;;;;;AAMA,SAOEC,YACAC,YACAC,UACAC,OAAOC,MACPC,mBACAC,WACAC,cACAC,mBACAC,kBACAC,oBACK;AACP,SAASC,UAAUC,SAASC,eAAe;AA2CpC,IAAMC,MAAMC;AACZ,IAAMC,SAASC;AAgBf,IAAMC,MAAM,CAACC,SAAmBC,WAAWD,IAAAA;AAc3C,IAAME,MAAM,CAAuCC,SAAYC,KAA4BD,IAAAA;",
|
|
6
|
+
"names": ["DXN", "EchoObject", "EntityKind", "ObjectId", "Ref", "Ref$", "getTypeAnnotation", "getSchema", "getSchemaDXN", "getSchemaTypename", "getSchemaVersion", "isInstanceOf", "create", "create$", "makeRef", "ref", "makeRef", "create", "create$", "def", "meta", "EchoObject", "Ref", "self", "Ref$"]
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"inputs":{"packages/core/echo/echo/src/Database.ts":{"bytes":689,"imports":[],"format":"esm"},"packages/core/echo/echo/src/Queue.ts":{"bytes":671,"imports":[],"format":"esm"},"packages/core/echo/echo/src/Space.ts":{"bytes":671,"imports":[],"format":"esm"},"packages/core/echo/echo/src/Type.ts":{"bytes":6001,"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true}],"format":"esm"},"packages/core/echo/echo/src/index.ts":{"bytes":1157,"imports":[{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"packages/core/echo/echo/src/Database.ts","kind":"import-statement","original":"./Database"},{"path":"packages/core/echo/echo/src/Queue.ts","kind":"import-statement","original":"./Queue"},{"path":"packages/core/echo/echo/src/Space.ts","kind":"import-statement","original":"./Space"},{"path":"packages/core/echo/echo/src/Type.ts","kind":"import-statement","original":"./Type"}],"format":"esm"}},"outputs":{"packages/core/echo/echo/dist/lib/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":4021},"packages/core/echo/echo/dist/lib/node-esm/index.mjs":{"imports":[{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/live-object","kind":"import-statement","external":true}],"exports":["DXN","Database","Queue","Space","Type"],"entryPoint":"packages/core/echo/echo/src/index.ts","inputs":{"packages/core/echo/echo/src/index.ts":{"bytesInOutput":34},"packages/core/echo/echo/src/Database.ts":{"bytesInOutput":27},"packages/core/echo/echo/src/Queue.ts":{"bytesInOutput":24},"packages/core/echo/echo/src/Space.ts":{"bytesInOutput":24},"packages/core/echo/echo/src/Type.ts":{"bytesInOutput":744}},"bytes":1480}}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Database.d.ts","sourceRoot":"","sources":["../../../src/Database.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,WAAW,QAAQ,CAAC,GAAE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Queue.d.ts","sourceRoot":"","sources":["../../../src/Queue.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,WAAW,KAAK,CAAC,GAAE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Space.d.ts","sourceRoot":"","sources":["../../../src/Space.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,WAAW,KAAK,CAAC,GAAE"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type Schema } from 'effect';
|
|
2
|
+
import { type BaseSchema, type EchoSchema, type Expando as Expando$, type ImmutableSchema, type JsonSchemaType, type TypeMeta, EntityKind, ObjectId, Ref as Ref$, getTypeAnnotation, getSchema, getSchemaDXN, getSchemaTypename, getSchemaVersion, isInstanceOf } from '@dxos/echo-schema';
|
|
3
|
+
export type { TypeMeta as Meta, JsonSchemaType as JsonSchema };
|
|
4
|
+
export { EntityKind as Kind, ObjectId, getTypeAnnotation as getMeta, getSchema, getSchemaDXN as getDXN, getSchemaTypename as getTypename, getSchemaVersion as getVersion, isInstanceOf as instanceOf, };
|
|
5
|
+
/**
|
|
6
|
+
* Type API.
|
|
7
|
+
*
|
|
8
|
+
* @category api namespace
|
|
9
|
+
* @since 0.9.0
|
|
10
|
+
*/
|
|
11
|
+
export declare namespace Type {
|
|
12
|
+
/**
|
|
13
|
+
* A schema that can be extended with arbitrary properties.
|
|
14
|
+
*/
|
|
15
|
+
type Expando = Expando$;
|
|
16
|
+
type Abstract<T = any> = BaseSchema<T>;
|
|
17
|
+
type ImmutableType<T> = ImmutableSchema<T>;
|
|
18
|
+
type MutableType<T> = EchoSchema<T>;
|
|
19
|
+
}
|
|
20
|
+
export declare const ref: <T extends import("@dxos/echo-schema").BaseObject>(obj: T) => Ref$<T>;
|
|
21
|
+
export declare const create: {
|
|
22
|
+
<T extends import("@dxos/echo-schema").BaseObject>(obj: T): import("@dxos/live-object").ReactiveObject<T>;
|
|
23
|
+
<T extends import("@dxos/echo-schema").BaseObject>(schema: Schema.Schema<T, any, never>, obj: NoInfer<import("@dxos/echo-schema").ExcludeId<T>>, meta?: import("@dxos/echo-schema").ObjectMeta): import("@dxos/live-object").ReactiveObject<T>;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Defines an ECHO type.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* const Org = S.Struct({
|
|
31
|
+
* name: S.String,
|
|
32
|
+
* }).pipe(Type.def({ typename: 'example.com/type/Org', version: '1.0.0' }));
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare const def: (meta: TypeMeta) => <Self extends Schema.Schema.Any>(self: Self) => import("@dxos/echo-schema").EchoObjectSchema<Self>;
|
|
36
|
+
/**
|
|
37
|
+
* Defines a reference to an ECHO object.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* import { Type } from '@dxos/echo';
|
|
42
|
+
* const Contact = S.Struct({
|
|
43
|
+
* name: S.String,
|
|
44
|
+
* employer: Type.Ref(Org),
|
|
45
|
+
* }).pipe(Type.def({ typename: 'example.com/type/Contact', version: '1.0.0' }));
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare const Ref: <S extends Schema.Schema.AnyNoContext>(self: S) => import("@dxos/echo-schema").Ref$<Schema.Schema.Type<S>>;
|
|
49
|
+
//# sourceMappingURL=Type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Type.d.ts","sourceRoot":"","sources":["../../../src/Type.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,EACL,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,OAAO,IAAI,QAAQ,EACxB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,QAAQ,EAEb,UAAU,EACV,QAAQ,EACR,GAAG,IAAI,IAAI,EACX,iBAAiB,EACjB,SAAS,EACT,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACb,MAAM,mBAAmB,CAAC;AAW3B,YAAY,EAAE,QAAQ,IAAI,IAAI,EAAE,cAAc,IAAI,UAAU,EAAE,CAAC;AAC/D,OAAO,EACL,UAAU,IAAI,IAAI,EAClB,QAAQ,EACR,iBAAiB,IAAI,OAAO,EAC5B,SAAS,EACT,YAAY,IAAI,MAAM,EACtB,iBAAiB,IAAI,WAAW,EAChC,gBAAgB,IAAI,UAAU,EAC9B,YAAY,IAAI,UAAU,GAC3B,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,OAAO,WAAW,IAAI,CAAC;IAC5B;;OAEG;IACH,KAAY,OAAO,GAAG,QAAQ,CAAC;IAE/B,KAAY,QAAQ,CAAC,CAAC,GAAG,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;IAC9C,KAAY,aAAa,CAAC,CAAC,IAAI,eAAe,CAAC,CAAC,CAAC,CAAC;IAClD,KAAY,WAAW,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;CAC5C;AAMD,eAAO,MAAM,GAAG,uEAAU,CAAC;AAC3B,eAAO,MAAM,MAAM;;;CAAU,CAAC;AAM9B;;;;;;;;;GASG;AACH,eAAO,MAAM,GAAG,SAAU,QAAQ,uGAAqB,CAAC;AAExD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,GAAG,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,CAAC,YAAY,QAAQ,CAAC,4DAAsC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.test.d.ts","sourceRoot":"","sources":["../../../src/api.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAEjC,OAAO,EAAE,GAAG,EAAE,CAAC;AAEf,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":"5.7.3"}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dxos/echo",
|
|
3
|
+
"version": "0.8.1-staging.31c3ee1",
|
|
4
|
+
"description": "ECHO API",
|
|
5
|
+
"homepage": "https://dxos.org",
|
|
6
|
+
"bugs": "https://github.com/dxos/dxos/issues",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"author": "info@dxos.org",
|
|
9
|
+
"sideEffects": true,
|
|
10
|
+
"type": "module",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/types/src/index.d.ts",
|
|
14
|
+
"browser": "./dist/lib/browser/index.mjs",
|
|
15
|
+
"node": "./dist/lib/node-esm/index.mjs"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"types": "dist/types/src/index.d.ts",
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"src"
|
|
22
|
+
],
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@preact/signals-core": "^1.6.0",
|
|
25
|
+
"effect": "3.13.3",
|
|
26
|
+
"@dxos/debug": "0.8.1-staging.31c3ee1",
|
|
27
|
+
"@dxos/echo-db": "0.8.1-staging.31c3ee1",
|
|
28
|
+
"@dxos/echo-signals": "0.8.1-staging.31c3ee1",
|
|
29
|
+
"@dxos/echo-schema": "0.8.1-staging.31c3ee1",
|
|
30
|
+
"@dxos/echo-protocol": "0.8.1-staging.31c3ee1",
|
|
31
|
+
"@dxos/effect": "0.8.1-staging.31c3ee1",
|
|
32
|
+
"@dxos/invariant": "0.8.1-staging.31c3ee1",
|
|
33
|
+
"@dxos/keys": "0.8.1-staging.31c3ee1",
|
|
34
|
+
"@dxos/live-object": "0.8.1-staging.31c3ee1",
|
|
35
|
+
"@dxos/log": "0.8.1-staging.31c3ee1",
|
|
36
|
+
"@dxos/node-std": "0.8.1-staging.31c3ee1",
|
|
37
|
+
"@dxos/util": "0.8.1-staging.31c3ee1"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"beast": {}
|
|
43
|
+
}
|
package/src/Database.ts
ADDED
package/src/Queue.ts
ADDED
package/src/Space.ts
ADDED
package/src/Type.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Schema } from 'effect';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
type BaseSchema,
|
|
9
|
+
type EchoSchema,
|
|
10
|
+
type Expando as Expando$,
|
|
11
|
+
type ImmutableSchema,
|
|
12
|
+
type JsonSchemaType,
|
|
13
|
+
type TypeMeta,
|
|
14
|
+
EchoObject,
|
|
15
|
+
EntityKind,
|
|
16
|
+
ObjectId,
|
|
17
|
+
Ref as Ref$,
|
|
18
|
+
getTypeAnnotation,
|
|
19
|
+
getSchema,
|
|
20
|
+
getSchemaDXN,
|
|
21
|
+
getSchemaTypename,
|
|
22
|
+
getSchemaVersion,
|
|
23
|
+
isInstanceOf,
|
|
24
|
+
} from '@dxos/echo-schema';
|
|
25
|
+
import { create as create$, makeRef } from '@dxos/live-object';
|
|
26
|
+
|
|
27
|
+
// NOTES:
|
|
28
|
+
// - New Echo package and namespaces allow for incremental migration; vastly simplifies imports.
|
|
29
|
+
// - Split into separate ECHO namespaces: Database, Space, Type, Query, Queue.
|
|
30
|
+
// - Example; import { Database, Type, Query, Queue } from '@dxos/echo';
|
|
31
|
+
// - Use `declare namespace` for types (no code is generated). See Effect pattern, where Schema is a namespace, interface, and function.
|
|
32
|
+
// - Test with @dxos/schema/testing types.
|
|
33
|
+
// - Define user (Composer) types in namespace (e.g., of plugin) and drop Type suffix; remove all deprecated Braneframe types.
|
|
34
|
+
|
|
35
|
+
export type { TypeMeta as Meta, JsonSchemaType as JsonSchema };
|
|
36
|
+
export {
|
|
37
|
+
EntityKind as Kind,
|
|
38
|
+
ObjectId,
|
|
39
|
+
getTypeAnnotation as getMeta,
|
|
40
|
+
getSchema,
|
|
41
|
+
getSchemaDXN as getDXN,
|
|
42
|
+
getSchemaTypename as getTypename,
|
|
43
|
+
getSchemaVersion as getVersion,
|
|
44
|
+
isInstanceOf as instanceOf,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Type API.
|
|
49
|
+
*
|
|
50
|
+
* @category api namespace
|
|
51
|
+
* @since 0.9.0
|
|
52
|
+
*/
|
|
53
|
+
export declare namespace Type {
|
|
54
|
+
/**
|
|
55
|
+
* A schema that can be extended with arbitrary properties.
|
|
56
|
+
*/
|
|
57
|
+
export type Expando = Expando$;
|
|
58
|
+
|
|
59
|
+
export type Abstract<T = any> = BaseSchema<T>;
|
|
60
|
+
export type ImmutableType<T> = ImmutableSchema<T>;
|
|
61
|
+
export type MutableType<T> = EchoSchema<T>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
//
|
|
65
|
+
// Constructors
|
|
66
|
+
//
|
|
67
|
+
|
|
68
|
+
export const ref = makeRef;
|
|
69
|
+
export const create = create$;
|
|
70
|
+
|
|
71
|
+
//
|
|
72
|
+
// Combinators
|
|
73
|
+
//
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Defines an ECHO type.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```ts
|
|
80
|
+
* const Org = S.Struct({
|
|
81
|
+
* name: S.String,
|
|
82
|
+
* }).pipe(Type.def({ typename: 'example.com/type/Org', version: '1.0.0' }));
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export const def = (meta: TypeMeta) => EchoObject(meta);
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Defines a reference to an ECHO object.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* import { Type } from '@dxos/echo';
|
|
93
|
+
* const Contact = S.Struct({
|
|
94
|
+
* name: S.String,
|
|
95
|
+
* employer: Type.Ref(Org),
|
|
96
|
+
* }).pipe(Type.def({ typename: 'example.com/type/Contact', version: '1.0.0' }));
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export const Ref = <S extends Schema.Schema.AnyNoContext>(self: S) => Ref$<Schema.Schema.Type<S>>(self);
|
package/src/api.test.ts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Schema as S } from 'effect';
|
|
6
|
+
import { describe, test } from 'vitest';
|
|
7
|
+
|
|
8
|
+
import { raise } from '@dxos/debug';
|
|
9
|
+
import { FormatEnum, FormatAnnotation } from '@dxos/echo-schema';
|
|
10
|
+
|
|
11
|
+
// Deliberately testing top-level import as if external consumer for @dxos/echo.
|
|
12
|
+
import { Type } from '.';
|
|
13
|
+
|
|
14
|
+
namespace Testing {
|
|
15
|
+
export const Org = S.Struct({
|
|
16
|
+
id: Type.ObjectId,
|
|
17
|
+
name: S.String,
|
|
18
|
+
}).pipe(
|
|
19
|
+
Type.def({
|
|
20
|
+
typename: 'example.com/type/Org',
|
|
21
|
+
version: '0.1.0',
|
|
22
|
+
}),
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
export interface Org extends S.Schema.Type<typeof Org> {}
|
|
26
|
+
|
|
27
|
+
export const Contact = S.Struct({
|
|
28
|
+
name: S.String,
|
|
29
|
+
dob: S.optional(S.String),
|
|
30
|
+
email: S.optional(S.String.pipe(FormatAnnotation.set(FormatEnum.Email))),
|
|
31
|
+
org: S.optional(Type.Ref(Org)),
|
|
32
|
+
}).pipe(
|
|
33
|
+
Type.def({
|
|
34
|
+
typename: 'example.com/type/Contact',
|
|
35
|
+
version: '0.1.0',
|
|
36
|
+
}),
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
export interface Contact extends S.Schema.Type<typeof Contact> {}
|
|
40
|
+
|
|
41
|
+
export const Message = S.Struct({
|
|
42
|
+
// TODO(burdon): Support S.Date; Custom Timestamp (with defaults).
|
|
43
|
+
// TODO(burdon): Support defaults (update create and createStatic).
|
|
44
|
+
timestamp: S.String.pipe(
|
|
45
|
+
S.propertySignature,
|
|
46
|
+
S.withConstructorDefault(() => new Date().toISOString()),
|
|
47
|
+
),
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// TODO(burdon): Fix (Type.def currently removes TypeLiteral that implements the `make` function)..
|
|
51
|
+
// }).pipe(
|
|
52
|
+
// Type.def({
|
|
53
|
+
// typename: 'example.com/type/Message',
|
|
54
|
+
// version: '0.1.0',
|
|
55
|
+
// }),
|
|
56
|
+
// );
|
|
57
|
+
|
|
58
|
+
export interface Message extends S.Schema.Type<typeof Message> {}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
describe('Experimental API review', () => {
|
|
62
|
+
test('type checks', ({ expect }) => {
|
|
63
|
+
const contact = Type.create(Testing.Contact, { name: 'Test' });
|
|
64
|
+
const type: S.Schema<Testing.Contact> = Type.getSchema(contact) ?? raise(new Error('No schema found'));
|
|
65
|
+
|
|
66
|
+
expect(Type.getDXN(type)?.typename).to.eq(Testing.Contact.typename);
|
|
67
|
+
expect(Type.getTypename(type)).to.eq('example.com/type/Contact');
|
|
68
|
+
expect(Type.getVersion(type)).to.eq('0.1.0');
|
|
69
|
+
expect(Type.getMeta(type)).to.deep.eq({
|
|
70
|
+
kind: Type.Kind.Object,
|
|
71
|
+
typename: 'example.com/type/Contact',
|
|
72
|
+
version: '0.1.0',
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('instance checks', ({ expect }) => {
|
|
77
|
+
// TODO(burdon): Implement.
|
|
78
|
+
// const org = Org.create({ name: 'DXOS' });
|
|
79
|
+
const org = Type.create(Testing.Org, { name: 'DXOS' });
|
|
80
|
+
const contact = Type.create(Testing.Contact, { name: 'Test', org: Type.ref(org) });
|
|
81
|
+
|
|
82
|
+
expect(S.is(Testing.Contact)(contact)).to.be.true;
|
|
83
|
+
expect(Testing.Contact.instanceOf(contact)).to.be.true;
|
|
84
|
+
expect(Type.instanceOf(Testing.Contact, contact)).to.be.true;
|
|
85
|
+
expect(Type.instanceOf(Testing.Org, contact.org?.target)).to.be.true;
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test('default props', ({ expect }) => {
|
|
89
|
+
// TODO(burdon): Doesn't work after pipe(Type.def).
|
|
90
|
+
// Property 'make' does not exist on type 'EchoObjectSchema<Struct<{ timestamp: PropertySignature<":", string, never, ":", string, true, never>; }>>'.ts(2339)
|
|
91
|
+
const message = Type.create(Testing.Message, Testing.Message.make({}));
|
|
92
|
+
expect(message.timestamp).to.exist;
|
|
93
|
+
});
|
|
94
|
+
});
|
package/src/index.ts
ADDED