@ekairos/domain 1.21.0 → 1.21.3-beta.0

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/index.js DELETED
@@ -1,203 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.domain = domain;
4
- const core_1 = require("@instantdb/core");
5
- function makeInstance(def) {
6
- function schema() {
7
- return core_1.i.schema({
8
- entities: def.entities,
9
- links: def.links,
10
- rooms: def.rooms,
11
- });
12
- }
13
- function compose(other) {
14
- const otherDef = "schema" in other
15
- ? { entities: other.entities, links: other.links, rooms: other.rooms }
16
- : other;
17
- const mergedEntities = { ...def.entities, ...otherDef.entities };
18
- const mergedLinks = { ...def.links, ...otherDef.links };
19
- const mergedRooms = { ...def.rooms, ...otherDef.rooms };
20
- return makeInstance({
21
- entities: mergedEntities,
22
- links: mergedLinks,
23
- rooms: mergedRooms,
24
- });
25
- }
26
- return {
27
- entities: def.entities,
28
- links: def.links,
29
- rooms: def.rooms,
30
- schema,
31
- compose,
32
- };
33
- }
34
- // Impl
35
- function domain(arg) {
36
- if (typeof arg === "object" && arg !== null) {
37
- // classic API path: def provided directly
38
- const def = arg;
39
- return makeInstance(def);
40
- }
41
- // builder API - runtime state tracks accumulated dependencies
42
- // Support lazy includes for circular dependencies by storing references and resolving at schema()/toInstantSchema() time
43
- // AL preserves literal link keys from included domains
44
- function createBuilder(deps, linkDeps, lazyIncludes = []) {
45
- return {
46
- includes(other) {
47
- // Support lazy includes via function for circular dependencies
48
- if (typeof other === 'function') {
49
- const lazyGetter = () => {
50
- try {
51
- return other();
52
- }
53
- catch (e) {
54
- return undefined;
55
- }
56
- };
57
- // Preserve link literal keys using MergeLinks
58
- return createBuilder(deps, linkDeps, [...lazyIncludes, lazyGetter]);
59
- }
60
- // If other is undefined (circular dependency), store a lazy getter
61
- // Entities will be resolved from app domain composition at toInstantSchema() time
62
- if (!other || other === undefined) {
63
- // Create a lazy getter that returns undefined
64
- // Entities will be available from app domain's merged entities when toInstantSchema() is called
65
- const lazyGetter = () => undefined;
66
- // Preserve link literal keys
67
- return createBuilder(deps, linkDeps, [...lazyIncludes, lazyGetter]);
68
- }
69
- // Try to get entities and links immediately
70
- try {
71
- const entities = other.entities;
72
- if (!entities) {
73
- // If entities don't exist yet, store as lazy
74
- const lazyGetter = () => other;
75
- // Preserve link literal keys
76
- return createBuilder(deps, linkDeps, [...lazyIncludes, lazyGetter]);
77
- }
78
- const links = other.links;
79
- const mergedEntities = { ...deps, ...entities };
80
- // Preserve literal link keys by merging directly (not casting to LinksDef)
81
- const mergedLinks = (links ? { ...linkDeps, ...links } : { ...linkDeps });
82
- return createBuilder(mergedEntities, mergedLinks, lazyIncludes);
83
- }
84
- catch (e) {
85
- // If accessing entities throws, store as lazy
86
- const lazyGetter = () => other;
87
- // Preserve link literal keys
88
- return createBuilder(deps, linkDeps, [...lazyIncludes, lazyGetter]);
89
- }
90
- },
91
- schema(def) {
92
- // Resolve lazy includes at schema() time (when all domains should be initialized)
93
- // This handles circular dependencies by deferring entity resolution
94
- let resolvedDeps = { ...deps };
95
- // Preserve literal link keys from accumulated links
96
- let resolvedLinks = { ...linkDeps };
97
- for (const lazyGetter of lazyIncludes) {
98
- try {
99
- const other = lazyGetter();
100
- if (other) {
101
- const entities = other.entities;
102
- if (entities) {
103
- resolvedDeps = { ...resolvedDeps, ...entities };
104
- }
105
- const links = other.links;
106
- if (links) {
107
- // Merge links preserving literal keys
108
- resolvedLinks = { ...resolvedLinks, ...links };
109
- }
110
- }
111
- }
112
- catch (e) {
113
- // If lazy resolution fails, continue - entities might be available via string references
114
- // This is expected for circular dependencies that will be resolved when all domains are composed
115
- }
116
- }
117
- // Runtime merge for output; compile-time validation handled by types above
118
- const allEntities = { ...resolvedDeps, ...def.entities };
119
- // allLinks contains merged links from included domains + current domain
120
- // Preserve literal link keys (owner, related, parent, etc.) by using MergeLinks
121
- const allLinks = { ...resolvedLinks, ...def.links };
122
- return {
123
- entities: allEntities,
124
- // Strip base phantom from public type so it's assignable to i.schema()
125
- links: allLinks,
126
- rooms: def.rooms,
127
- // Add originalEntities for type-safe access to original entity definitions
128
- originalEntities: allEntities,
129
- toInstantSchema: (() => {
130
- // Capture allEntities and allLinks in closure to avoid TypeScript scoping issues
131
- const capturedEntities = allEntities;
132
- const capturedLinks = allLinks;
133
- return () => {
134
- const { i } = require("@instantdb/core");
135
- // Final resolution: capturedEntities contains merged entities from all includes()
136
- // For app domain, this includes all domains, so all entities are available
137
- // Resolve any remaining lazy includes that couldn't be resolved at schema() time
138
- let finalEntities = { ...capturedEntities };
139
- // Preserve literal link keys from capturedLinks
140
- let finalLinks = { ...capturedLinks };
141
- // Try to resolve lazy includes one more time (domains should be initialized by now)
142
- for (const lazyGetter of lazyIncludes) {
143
- try {
144
- const other = lazyGetter();
145
- if (other) {
146
- const entities = other.entities;
147
- if (entities) {
148
- // Merge entities that weren't available during schema() call
149
- finalEntities = { ...finalEntities, ...entities };
150
- }
151
- const links = other.links;
152
- if (links) {
153
- // Merge links preserving literal keys (owner, related, parent, etc.)
154
- finalLinks = { ...finalLinks, ...links };
155
- }
156
- }
157
- }
158
- catch (e) {
159
- // If still can't resolve, entities should already be in allEntities from app domain composition
160
- }
161
- }
162
- // Include base entities ($users, $files) that InstantDB manages
163
- // These need to be explicitly included since InstantDB doesn't auto-add them
164
- const baseEntities = {
165
- $users: i.entity({
166
- email: i.string().optional().indexed(),
167
- }),
168
- $files: i.entity({
169
- path: i.string(),
170
- url: i.string().optional(),
171
- contentType: i.string().optional(),
172
- size: i.number().optional(),
173
- }),
174
- };
175
- // Merge base entities with user entities, user entities take precedence
176
- const allEntitiesWithBase = { ...baseEntities, ...finalEntities };
177
- // Create schema with merged links - preserve literal link keys
178
- // The actual links object has literal keys (owner, related, parent, etc.)
179
- // that need to be preserved for query validation
180
- const schemaResult = i.schema({
181
- entities: allEntitiesWithBase,
182
- links: finalLinks,
183
- rooms: def.rooms,
184
- });
185
- // Return schema result - i.schema() enriches entities with link labels automatically
186
- // The type system should preserve this enrichment through the return type of toInstantSchema()
187
- // which uses ReturnType<typeof i.schema<WithBase<E>, L, R>> where L is MergeLinks<AL, LL>
188
- // This preserves both the enriched entities and the literal link keys
189
- return schemaResult;
190
- };
191
- })(),
192
- };
193
- },
194
- };
195
- }
196
- // Default include: start with an empty entities object
197
- // Base entities ($users, $files) are added at toInstantSchema() time to ensure they're always available
198
- // This allows links to reference them even when they're not explicitly defined in domains
199
- const base = core_1.i.schema({ entities: {}, links: {}, rooms: {} });
200
- const baseEntities = { ...base.entities };
201
- return createBuilder(baseEntities, {});
202
- }
203
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAkKA,wBAiNC;AAnXD,0CAAoC;AAkHpC,SAAS,YAAY,CACnB,GAA8B;IAE9B,SAAS,MAAM;QACb,OAAO,QAAC,CAAC,MAAM,CAAC;YACd,QAAQ,EAAE,GAAG,CAAC,QAAa;YAC3B,KAAK,EAAE,GAAG,CAAC,KAAU;YACrB,KAAK,EAAE,GAAG,CAAC,KAAU;SACtB,CAAC,CAAC;IACL,CAAC;IAED,SAAS,OAAO,CACd,KAAgE;QAEhE,MAAM,QAAQ,GACZ,QAAQ,IAAI,KAAK;YACf,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE;YACtE,CAAC,CAAC,KAAK,CAAC;QAEZ,MAAM,cAAc,GAAG,EAAE,GAAG,GAAG,CAAC,QAAQ,EAAE,GAAG,QAAQ,CAAC,QAAQ,EAAY,CAAC;QAC3E,MAAM,WAAW,GAAG,EAAE,GAAI,GAAG,CAAC,KAAgB,EAAE,GAAI,QAAQ,CAAC,KAAgB,EAAsB,CAAC;QACpG,MAAM,WA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