@xnetjs/data 0.0.2 → 0.1.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.
Files changed (139) hide show
  1. package/README.md +112 -0
  2. package/dist/account-MWNCH4GJ.js +12 -0
  3. package/dist/account-ledger-R2GAFJL6.js +38 -0
  4. package/dist/auth/index.d.ts +420 -0
  5. package/dist/auth/index.js +102 -0
  6. package/dist/budget-NN7P35XP.js +12 -0
  7. package/dist/canvas-6WYBNH53.js +10 -0
  8. package/dist/channel-AT3LQF4A.js +12 -0
  9. package/dist/chat-message-DSVO72B3.js +10 -0
  10. package/dist/chunk-2ZNJWIQG.js +84 -0
  11. package/dist/chunk-3J3HILXO.js +46 -0
  12. package/dist/chunk-3RUDVTMH.js +5543 -0
  13. package/dist/chunk-4EYKGTSQ.js +49 -0
  14. package/dist/chunk-53F4PRNC.js +32 -0
  15. package/dist/chunk-5EXHNXPL.js +48 -0
  16. package/dist/{chunk-BQBPA5HS.js → chunk-5HC5NO57.js} +16 -2
  17. package/dist/chunk-6KLGA6IR.js +47 -0
  18. package/dist/chunk-6OMG4I7M.js +41 -0
  19. package/dist/chunk-7PDRDSFH.js +69 -0
  20. package/dist/chunk-BQLQSWKZ.js +232 -0
  21. package/dist/chunk-BY5O6LNC.js +380 -0
  22. package/dist/chunk-DCTRX6II.js +40 -0
  23. package/dist/{chunk-VYR5GPJP.js → chunk-DWEXKD6E.js} +9 -3
  24. package/dist/chunk-EBNMV2VO.js +896 -0
  25. package/dist/chunk-FVEACSKE.js +102 -0
  26. package/dist/chunk-GU6THOAB.js +45 -0
  27. package/dist/chunk-H4GA4BBK.js +75 -0
  28. package/dist/chunk-IJ44LR7N.js +76 -0
  29. package/dist/chunk-J4ANIXIV.js +402 -0
  30. package/dist/chunk-JDFNMFOZ.js +45 -0
  31. package/dist/chunk-K7DOZWWT.js +1811 -0
  32. package/dist/chunk-KQAT4XBL.js +49 -0
  33. package/dist/chunk-KQUALW4O.js +183 -0
  34. package/dist/chunk-LYSWLCOI.js +47 -0
  35. package/dist/chunk-MBTUO3ZL.js +65 -0
  36. package/dist/chunk-NI4FHG2K.js +52 -0
  37. package/dist/chunk-OCMSAKWV.js +78 -0
  38. package/dist/chunk-OGJCRNGE.js +57 -0
  39. package/dist/chunk-OPPHF3TF.js +143 -0
  40. package/dist/{chunk-IDMBCRUC.js → chunk-OSAWNZVM.js} +1 -1
  41. package/dist/chunk-PMUQACPY.js +33 -0
  42. package/dist/chunk-PNESGUH5.js +63 -0
  43. package/dist/chunk-Q3IEGH4B.js +51 -0
  44. package/dist/chunk-QJW5LDP4.js +52 -0
  45. package/dist/chunk-QWFTRZQT.js +142 -0
  46. package/dist/{chunk-SZC345Z2.js → chunk-RL64OJJ5.js} +1025 -1110
  47. package/dist/chunk-S5RP5RKY.js +416 -0
  48. package/dist/chunk-S6U6TCMN.js +722 -0
  49. package/dist/chunk-SVNGSZZA.js +69 -0
  50. package/dist/chunk-T5AZAOG5.js +54 -0
  51. package/dist/chunk-TCTZW4A6.js +42 -0
  52. package/dist/chunk-U64CW73O.js +109 -0
  53. package/dist/chunk-UDWKWTAX.js +6526 -0
  54. package/dist/chunk-UQM3G5A2.js +148 -0
  55. package/dist/chunk-VQ7JHB67.js +57 -0
  56. package/dist/chunk-W7EBL7ZU.js +73 -0
  57. package/dist/chunk-WEPK7SZF.js +65 -0
  58. package/dist/chunk-XHEA5UER.js +75 -0
  59. package/dist/chunk-XMSKJ5PV.js +66 -0
  60. package/dist/chunk-XROI44ZP.js +64 -0
  61. package/dist/chunk-Y3S5SRVM.js +45 -0
  62. package/dist/chunk-YEFKQYKA.js +43 -0
  63. package/dist/chunk-YSUIXD2Y.js +105 -0
  64. package/dist/chunk-ZCOFZY5M.js +70 -0
  65. package/dist/chunk-ZLU4Y3O2.js +50 -0
  66. package/dist/chunk-ZPZ7XDA6.js +54 -0
  67. package/dist/chunk-ZZ6TWKGS.js +40 -0
  68. package/dist/clone-C0Jhk2UN.d.ts +2205 -0
  69. package/dist/comment-QSWYAQVS.js +10 -0
  70. package/dist/crm-L5RYAAF3.js +68 -0
  71. package/dist/dashboard-JMKTTRA7.js +10 -0
  72. package/dist/database/index.d.ts +882 -0
  73. package/dist/database/index.js +523 -0
  74. package/dist/database-GIXSPZJW.js +10 -0
  75. package/dist/database-field-3EPAMZUR.js +10 -0
  76. package/dist/database-row-6Q6TRVE4.js +10 -0
  77. package/dist/database-select-option-BBBJFLLH.js +10 -0
  78. package/dist/database-view-5PLSOBI2.js +10 -0
  79. package/dist/experiment-DOVOZ34Y.js +10 -0
  80. package/dist/external-item-P2E5X7BZ.js +14 -0
  81. package/dist/external-reference-7BSFF6SA.js +8 -0
  82. package/dist/feed-2IXHHP6O.js +12 -0
  83. package/dist/feed-item-DPE6LN7I.js +12 -0
  84. package/dist/folder-6KM3KYD5.js +21 -0
  85. package/dist/game-5AK5XWBR.js +50 -0
  86. package/dist/grant-WTQSNT5A.js +8 -0
  87. package/dist/grant-expiration-cleaner-CY6BcmlR.d.ts +249 -0
  88. package/dist/import-batch-IXBJLQPJ.js +12 -0
  89. package/dist/inbox-state-E5NSVOGP.js +12 -0
  90. package/dist/index.d.ts +224 -4548
  91. package/dist/index.js +2252 -4754
  92. package/dist/map-RG5Y3CPC.js +10 -0
  93. package/dist/media-asset-QTCGLIZA.js +8 -0
  94. package/dist/memory-PNRTMBZO.js +12 -0
  95. package/dist/metric-65SVOX5C.js +10 -0
  96. package/dist/milestone-XEO6ZGDG.js +12 -0
  97. package/dist/moderation-FFHETMRB.js +30 -0
  98. package/dist/observation-2Y3QKUXM.js +10 -0
  99. package/dist/page-2V27JGKJ.js +10 -0
  100. package/dist/posting-GBOSZCMZ.js +12 -0
  101. package/dist/profile-BLLDWIDK.js +8 -0
  102. package/dist/project-CQL5LN26.js +10 -0
  103. package/dist/query-ast-C3m6kZYv.d.ts +226 -0
  104. package/dist/reaction-T2DTJBBV.js +10 -0
  105. package/dist/registry-DunPv__d.d.ts +99 -0
  106. package/dist/saved-view-4R2DBCL3.js +10 -0
  107. package/dist/schema/index.d.ts +6489 -0
  108. package/dist/schema/index.js +677 -0
  109. package/dist/schema-extension-LNRF2YRD.js +18 -0
  110. package/dist/space-IJU24PBH.js +42 -0
  111. package/dist/space-membership-DEUMM7NV.js +14 -0
  112. package/dist/store/index.d.ts +518 -0
  113. package/dist/store/index.js +135 -0
  114. package/dist/store-DtIDjk7c.d.ts +355 -0
  115. package/dist/sync/awareness.d.ts +69 -0
  116. package/dist/sync/awareness.js +20 -0
  117. package/dist/system-ILHCZOVO.js +38 -0
  118. package/dist/tag-SKCHM3U5.js +16 -0
  119. package/dist/task-7AOBP7WC.js +16 -0
  120. package/dist/task-view-NUGKELJP.js +10 -0
  121. package/dist/transaction-ZDSEGDIR.js +12 -0
  122. package/dist/transcription-PSCLDAGX.js +12 -0
  123. package/dist/types-S-BJAKyK.d.ts +1576 -0
  124. package/dist/updates.d.ts +44 -0
  125. package/dist/updates.js +16 -0
  126. package/dist/user-widget-RLY2N46A.js +8 -0
  127. package/dist/view-types-DSde-uT_.d.ts +316 -0
  128. package/package.json +32 -9
  129. package/dist/canvas-HSIKIQFK.js +0 -7
  130. package/dist/chunk-2L5ZUGG5.js +0 -53
  131. package/dist/chunk-4MTS5KAQ.js +0 -22
  132. package/dist/chunk-GZHARFKC.js +0 -25
  133. package/dist/chunk-WKIKJTI2.js +0 -45
  134. package/dist/comment-277JD7DV.js +0 -7
  135. package/dist/database-W3KEHLI3.js +0 -7
  136. package/dist/database-row-3O2QSNZN.js +0 -7
  137. package/dist/grant-QVZ454YC.js +0 -7
  138. package/dist/page-O4WTOIEO.js +0 -7
  139. package/dist/task-SEKAYJH7.js +0 -7
@@ -0,0 +1,896 @@
1
+ import {
2
+ serializeAuthorization,
3
+ validateAuthorization,
4
+ warnLegacySchema
5
+ } from "./chunk-RL64OJJ5.js";
6
+
7
+ // src/schema/node.ts
8
+ import { nanoid } from "nanoid";
9
+ var DEFAULT_SCHEMA_VERSION = "1.0.0";
10
+ function parseSchemaIRI(iri) {
11
+ const match = iri.match(/^(xnet:\/\/[^/]+\/)([^@]+)(?:@(.+))?$/);
12
+ if (!match) {
13
+ return {
14
+ iri,
15
+ baseIRI: iri,
16
+ namespace: "",
17
+ name: iri,
18
+ version: DEFAULT_SCHEMA_VERSION,
19
+ hasExplicitVersion: false
20
+ };
21
+ }
22
+ const [, namespace, name, version] = match;
23
+ const hasExplicitVersion = version !== void 0;
24
+ const resolvedVersion = version ?? DEFAULT_SCHEMA_VERSION;
25
+ const baseIRI = `${namespace}${name}`;
26
+ return {
27
+ iri: hasExplicitVersion ? iri : `${baseIRI}@${resolvedVersion}`,
28
+ baseIRI,
29
+ namespace,
30
+ name,
31
+ version: resolvedVersion,
32
+ hasExplicitVersion
33
+ };
34
+ }
35
+ function buildSchemaIRI(namespace, name, version) {
36
+ const v = version ?? DEFAULT_SCHEMA_VERSION;
37
+ return `${namespace}${name}@${v}`;
38
+ }
39
+ function normalizeSchemaIRI(iri) {
40
+ const parsed = parseSchemaIRI(iri);
41
+ return parsed.iri;
42
+ }
43
+ function getBaseSchemaIRI(iri) {
44
+ return parseSchemaIRI(iri).baseIRI;
45
+ }
46
+ function isSameSchema(iri1, iri2) {
47
+ return getBaseSchemaIRI(iri1) === getBaseSchemaIRI(iri2);
48
+ }
49
+ function getSchemaVersion(iri) {
50
+ return parseSchemaIRI(iri).version;
51
+ }
52
+ function isNode(value) {
53
+ if (typeof value !== "object" || value === null) return false;
54
+ const obj = value;
55
+ return typeof obj.id === "string" && typeof obj.schemaId === "string" && obj.schemaId.startsWith("xnet://") && typeof obj.createdAt === "number" && typeof obj.createdBy === "string" && obj.createdBy.startsWith("did:key:");
56
+ }
57
+ function createNodeId(length) {
58
+ return nanoid(length);
59
+ }
60
+
61
+ // src/schema/schemas/auth-exempt.ts
62
+ var AUTH_EXEMPT_SCHEMA_IRIS = /* @__PURE__ */ new Set([
63
+ "xnet://xnet.fyi/SpaceMembership@1.0.0",
64
+ "xnet://xnet.fyi/SpaceMembership",
65
+ "xnet://xnet.fyi/Grant@1.0.0",
66
+ "xnet://xnet.fyi/Grant",
67
+ "xnet://xnet.fyi/Profile@1.0.0",
68
+ "xnet://xnet.fyi/Profile",
69
+ "xnet://xnet.fyi/SchemaDefinition@1.0.0",
70
+ "xnet://xnet.fyi/SchemaDefinition",
71
+ "xnet://xnet.fyi/SchemaCompatibility@1.0.0",
72
+ "xnet://xnet.fyi/SchemaCompatibility",
73
+ "xnet://xnet.fyi/SyncPolicy@1.0.0",
74
+ "xnet://xnet.fyi/SyncPolicy",
75
+ "xnet://xnet.fyi/PresenceSummary@1.0.0",
76
+ "xnet://xnet.fyi/PresenceSummary",
77
+ // Account/device ledger (0149/0243) — controller-signed + epoch-gated, hub-enforced.
78
+ "xnet://xnet.fyi/AccountRecord@1.0.0",
79
+ "xnet://xnet.fyi/AccountRecord",
80
+ "xnet://xnet.fyi/DeviceRecord@1.0.0",
81
+ "xnet://xnet.fyi/DeviceRecord",
82
+ "xnet://xnet.fyi/RecoveryRecord@1.0.0",
83
+ "xnet://xnet.fyi/RecoveryRecord",
84
+ "xnet://xnet.fyi/RevocationRecord@1.0.0",
85
+ "xnet://xnet.fyi/RevocationRecord"
86
+ ]);
87
+ function isAuthExemptSchema(schemaId) {
88
+ return AUTH_EXEMPT_SCHEMA_IRIS.has(schemaId);
89
+ }
90
+
91
+ // src/schema/define.ts
92
+ var DEFAULT_SCHEMA_VERSION2 = "1.0.0";
93
+ function defineSchema(options) {
94
+ const version = options.version ?? DEFAULT_SCHEMA_VERSION2;
95
+ const schemaId = `${options.namespace}${options.name}@${version}`;
96
+ if (process.env.NODE_ENV !== "production") {
97
+ const REF_NAME_PATTERN = /(?:^target$|^inReplyTo$|^replyTo[A-Z].*(?:Id|Node)$|(?:parent|node|comment|task|page|database)(?:Id|Ref)$)/;
98
+ for (const [name, builder] of Object.entries(options.properties)) {
99
+ if (builder.definition.type === "text" && REF_NAME_PATTERN.test(name)) {
100
+ console.warn(
101
+ `[xNet Schema] "${options.name}.${name}" is a text() property whose name suggests it stores a reference. Consider using relation() for node references or person() for DIDs.`
102
+ );
103
+ }
104
+ }
105
+ }
106
+ const properties = Object.entries(options.properties).map(
107
+ ([name, builder]) => ({
108
+ "@id": `${schemaId}#${name}`,
109
+ name,
110
+ ...builder.definition
111
+ })
112
+ );
113
+ const propertyMap = Object.fromEntries(properties.map((property) => [property.name, property]));
114
+ if (options.authorization) {
115
+ const authResult = validateAuthorization(options.authorization, propertyMap);
116
+ if (!authResult.valid) {
117
+ const message = authResult.errors.map((error) => `${error.path}: [${error.code}] ${error.message}`).join(", ");
118
+ throw new Error(`Invalid authorization in schema '${options.name}': ${message}`);
119
+ }
120
+ }
121
+ const schema = {
122
+ "@id": schemaId,
123
+ "@type": "xnet://xnet.fyi/Schema",
124
+ name: options.name,
125
+ namespace: options.namespace,
126
+ version,
127
+ migrateFrom: options.migrateFrom,
128
+ properties,
129
+ extends: options.extends?.schema["@id"],
130
+ document: options.document,
131
+ authorization: options.authorization ? serializeAuthorization(options.authorization) : void 0
132
+ };
133
+ if (process.env.NODE_ENV === "development" && !isAuthExemptSchema(schemaId)) {
134
+ warnLegacySchema(schema);
135
+ }
136
+ function validate(node) {
137
+ const errors = [];
138
+ if (typeof node !== "object" || node === null) {
139
+ return { valid: false, errors: [{ path: "", message: "Node must be an object" }] };
140
+ }
141
+ const obj = node;
142
+ if (typeof obj.id !== "string") {
143
+ errors.push({ path: "id", message: "id is required and must be a string" });
144
+ }
145
+ if (obj.schemaId !== schemaId) {
146
+ errors.push({
147
+ path: "schemaId",
148
+ message: `schemaId must be '${schemaId}'`,
149
+ value: obj.schemaId
150
+ });
151
+ }
152
+ if (typeof obj.createdAt !== "number") {
153
+ errors.push({ path: "createdAt", message: "createdAt is required and must be a number" });
154
+ }
155
+ if (typeof obj.createdBy !== "string" || !obj.createdBy.startsWith("did:key:")) {
156
+ errors.push({ path: "createdBy", message: "createdBy must be a valid DID" });
157
+ }
158
+ for (const [name, builder] of Object.entries(options.properties)) {
159
+ const value = obj[name];
160
+ const isRequired = builder.definition.required;
161
+ if (value === void 0 || value === null) {
162
+ if (isRequired) {
163
+ errors.push({ path: name, message: `${name} is required` });
164
+ }
165
+ } else if (!builder.validate(value)) {
166
+ errors.push({ path: name, message: `${name} has invalid value`, value });
167
+ }
168
+ }
169
+ return { valid: errors.length === 0, errors };
170
+ }
171
+ function create(props, createOptions) {
172
+ const now = createOptions.createdAt ?? Date.now();
173
+ const id = createOptions.id ?? createNodeId();
174
+ const node = {
175
+ id,
176
+ schemaId,
177
+ createdAt: now,
178
+ createdBy: createOptions.createdBy
179
+ };
180
+ for (const [name, builder] of Object.entries(options.properties)) {
181
+ const rawValue = props[name];
182
+ const coerced = builder.coerce(rawValue);
183
+ if (coerced !== null) {
184
+ node[name] = coerced;
185
+ }
186
+ }
187
+ return node;
188
+ }
189
+ function is(node) {
190
+ return node.schemaId === schemaId;
191
+ }
192
+ return {
193
+ schema,
194
+ validate,
195
+ create,
196
+ is,
197
+ _schemaId: schemaId,
198
+ _properties: options.properties
199
+ };
200
+ }
201
+
202
+ // src/schema/properties/text.ts
203
+ function text(options = {}) {
204
+ return {
205
+ definition: {
206
+ type: "text",
207
+ required: options.required ?? false,
208
+ config: {
209
+ minLength: options.minLength,
210
+ maxLength: options.maxLength,
211
+ pattern: options.pattern?.source,
212
+ placeholder: options.placeholder
213
+ }
214
+ },
215
+ validate(value) {
216
+ if (value === null || value === void 0) {
217
+ return !options.required;
218
+ }
219
+ if (typeof value !== "string") return false;
220
+ if (options.minLength !== void 0 && value.length < options.minLength) return false;
221
+ if (options.maxLength !== void 0 && value.length > options.maxLength) return false;
222
+ if (options.pattern && !options.pattern.test(value)) return false;
223
+ return true;
224
+ },
225
+ coerce(value) {
226
+ if (value === null || value === void 0) return null;
227
+ return String(value);
228
+ },
229
+ _type: ""
230
+ };
231
+ }
232
+
233
+ // src/schema/properties/number.ts
234
+ function number(options = {}) {
235
+ return {
236
+ definition: {
237
+ type: "number",
238
+ required: options.required ?? false,
239
+ config: {
240
+ min: options.min,
241
+ max: options.max,
242
+ integer: options.integer
243
+ }
244
+ },
245
+ validate(value) {
246
+ if (value === null || value === void 0) {
247
+ return !options.required;
248
+ }
249
+ if (typeof value !== "number" || isNaN(value)) return false;
250
+ if (options.min !== void 0 && value < options.min) return false;
251
+ if (options.max !== void 0 && value > options.max) return false;
252
+ if (options.integer && !Number.isInteger(value)) return false;
253
+ return true;
254
+ },
255
+ coerce(value) {
256
+ if (value === null || value === void 0) return null;
257
+ const num = Number(value);
258
+ if (isNaN(num)) return null;
259
+ if (options.integer) return Math.round(num);
260
+ return num;
261
+ },
262
+ _type: 0
263
+ };
264
+ }
265
+
266
+ // src/schema/properties/checkbox.ts
267
+ function checkbox(options = {}) {
268
+ return {
269
+ definition: {
270
+ type: "checkbox",
271
+ required: options.required ?? false,
272
+ config: {
273
+ default: options.default
274
+ }
275
+ },
276
+ validate(value) {
277
+ if (value === null || value === void 0) {
278
+ return !options.required;
279
+ }
280
+ return typeof value === "boolean";
281
+ },
282
+ coerce(value) {
283
+ if (value === null || value === void 0) {
284
+ return options.default ?? null;
285
+ }
286
+ if (typeof value === "boolean") return value;
287
+ if (value === "true" || value === 1) return true;
288
+ if (value === "false" || value === 0) return false;
289
+ return Boolean(value);
290
+ },
291
+ _type: false
292
+ };
293
+ }
294
+
295
+ // src/schema/properties/json.ts
296
+ function isJsonValue(value, depth = 0) {
297
+ if (depth > 64) return false;
298
+ if (value === null) return true;
299
+ const t = typeof value;
300
+ if (t === "string" || t === "boolean") return true;
301
+ if (t === "number") return Number.isFinite(value);
302
+ if (Array.isArray(value)) {
303
+ return value.every((v) => isJsonValue(v, depth + 1));
304
+ }
305
+ if (t === "object") {
306
+ const proto = Object.getPrototypeOf(value);
307
+ if (proto !== Object.prototype && proto !== null) return false;
308
+ return Object.values(value).every((v) => isJsonValue(v, depth + 1));
309
+ }
310
+ return false;
311
+ }
312
+ function json(options = {}) {
313
+ return {
314
+ definition: {
315
+ type: "json",
316
+ required: options.required ?? false,
317
+ config: {}
318
+ },
319
+ validate(value) {
320
+ if (value === null || value === void 0) {
321
+ return !options.required;
322
+ }
323
+ return isJsonValue(value);
324
+ },
325
+ coerce(value) {
326
+ if (value === null || value === void 0) return null;
327
+ return value;
328
+ },
329
+ _type: void 0
330
+ };
331
+ }
332
+
333
+ // src/schema/properties/money.ts
334
+ function isMoneyValue(value) {
335
+ if (value === null || typeof value !== "object") return false;
336
+ const v = value;
337
+ return typeof v.amount === "number" && Number.isInteger(v.amount) && typeof v.currency === "string" && /^[A-Z]{3}$/.test(v.currency);
338
+ }
339
+ function money(options = {}) {
340
+ const currencyConstraint = options.currency?.toUpperCase();
341
+ return {
342
+ definition: {
343
+ type: "json",
344
+ required: options.required ?? false,
345
+ config: {
346
+ format: "money",
347
+ ...currencyConstraint !== void 0 && { currency: currencyConstraint }
348
+ }
349
+ },
350
+ validate(value) {
351
+ if (value === null || value === void 0) {
352
+ return !options.required;
353
+ }
354
+ if (!isMoneyValue(value)) return false;
355
+ if (currencyConstraint && value.currency !== currencyConstraint) return false;
356
+ return true;
357
+ },
358
+ coerce(value) {
359
+ if (value === null || value === void 0) return null;
360
+ if (typeof value !== "object") return null;
361
+ const v = value;
362
+ if (typeof v.amount !== "number" || isNaN(v.amount)) return null;
363
+ if (typeof v.currency !== "string" || !/^[A-Za-z]{3}$/.test(v.currency)) return null;
364
+ const currency = v.currency.toUpperCase();
365
+ if (currencyConstraint && currency !== currencyConstraint) return null;
366
+ return { amount: Math.round(v.amount), currency };
367
+ },
368
+ _type: { amount: 0, currency: "USD" }
369
+ };
370
+ }
371
+
372
+ // src/schema/properties/date.ts
373
+ function date(options = {}) {
374
+ return {
375
+ definition: {
376
+ type: "date",
377
+ required: options.required ?? false,
378
+ config: {
379
+ includeTime: options.includeTime ?? false
380
+ }
381
+ },
382
+ validate(value) {
383
+ if (value === null || value === void 0) {
384
+ return !options.required;
385
+ }
386
+ if (typeof value !== "number") return false;
387
+ return value >= 0 && value < 3250368e7;
388
+ },
389
+ coerce(value) {
390
+ if (value === null || value === void 0) return null;
391
+ if (typeof value === "number") {
392
+ return value;
393
+ }
394
+ if (value instanceof Date) {
395
+ return value.getTime();
396
+ }
397
+ if (typeof value === "string") {
398
+ const parsed = Date.parse(value);
399
+ if (!isNaN(parsed)) return parsed;
400
+ }
401
+ return null;
402
+ },
403
+ _type: 0
404
+ };
405
+ }
406
+
407
+ // src/schema/properties/dateRange.ts
408
+ function isValidDateRange(value) {
409
+ if (typeof value !== "object" || value === null) return false;
410
+ const obj = value;
411
+ if (typeof obj.start !== "string") return false;
412
+ if (!isValidDateString(obj.start)) return false;
413
+ if (obj.end !== void 0) {
414
+ if (typeof obj.end !== "string") return false;
415
+ if (!isValidDateString(obj.end)) return false;
416
+ }
417
+ return true;
418
+ }
419
+ function isValidDateString(str) {
420
+ const d = new Date(str);
421
+ return !isNaN(d.getTime());
422
+ }
423
+ function dateRange(options = {}) {
424
+ return {
425
+ definition: {
426
+ type: "dateRange",
427
+ required: options.required ?? false,
428
+ config: {
429
+ includeTime: options.includeTime ?? false
430
+ }
431
+ },
432
+ validate(value) {
433
+ if (value === null || value === void 0) {
434
+ return !options.required;
435
+ }
436
+ return isValidDateRange(value);
437
+ },
438
+ coerce(value) {
439
+ if (value === null || value === void 0) return null;
440
+ if (isValidDateRange(value)) {
441
+ return value;
442
+ }
443
+ if (typeof value === "object" && value !== null) {
444
+ const obj = value;
445
+ if (obj.start) {
446
+ const start = new Date(obj.start);
447
+ if (!isNaN(start.getTime())) {
448
+ const result = { start: start.toISOString() };
449
+ if (obj.end) {
450
+ const end = new Date(obj.end);
451
+ if (!isNaN(end.getTime())) {
452
+ result.end = end.toISOString();
453
+ }
454
+ }
455
+ return result;
456
+ }
457
+ }
458
+ }
459
+ return null;
460
+ },
461
+ _type: {}
462
+ };
463
+ }
464
+
465
+ // src/schema/properties/select.ts
466
+ function select(options) {
467
+ const validIds = new Set(options.options.map((o) => o.id));
468
+ return {
469
+ definition: {
470
+ type: "select",
471
+ required: options.required ?? false,
472
+ config: {
473
+ options: options.options,
474
+ default: options.default
475
+ }
476
+ },
477
+ validate(value) {
478
+ if (value === null || value === void 0) {
479
+ return !options.required;
480
+ }
481
+ return typeof value === "string" && validIds.has(value);
482
+ },
483
+ coerce(value) {
484
+ if (value === null || value === void 0) {
485
+ return options.default ?? null;
486
+ }
487
+ if (typeof value === "string" && validIds.has(value)) {
488
+ return value;
489
+ }
490
+ const byName = options.options.find(
491
+ (o) => o.name.toLowerCase() === String(value).toLowerCase()
492
+ );
493
+ if (byName) return byName.id;
494
+ return null;
495
+ },
496
+ _type: ""
497
+ };
498
+ }
499
+
500
+ // src/schema/properties/multiSelect.ts
501
+ function multiSelect(options) {
502
+ const validIds = new Set(options.options.map((o) => o.id));
503
+ return {
504
+ definition: {
505
+ type: "multiSelect",
506
+ required: options.required ?? false,
507
+ config: {
508
+ options: options.options,
509
+ default: options.default
510
+ }
511
+ },
512
+ validate(value) {
513
+ if (value === null || value === void 0) {
514
+ return !options.required;
515
+ }
516
+ if (!Array.isArray(value)) return false;
517
+ return value.every((v) => typeof v === "string" && validIds.has(v));
518
+ },
519
+ coerce(value) {
520
+ if (value === null || value === void 0) {
521
+ return options.default ?? [];
522
+ }
523
+ if (!Array.isArray(value)) {
524
+ if (typeof value === "string" && validIds.has(value)) {
525
+ return [value];
526
+ }
527
+ return null;
528
+ }
529
+ const result = [];
530
+ for (const v of value) {
531
+ if (typeof v === "string" && validIds.has(v)) {
532
+ result.push(v);
533
+ } else {
534
+ const byName = options.options.find(
535
+ (o) => o.name.toLowerCase() === String(v).toLowerCase()
536
+ );
537
+ if (byName) result.push(byName.id);
538
+ }
539
+ }
540
+ return result;
541
+ },
542
+ _type: []
543
+ };
544
+ }
545
+
546
+ // src/schema/properties/person.ts
547
+ var DID_PATTERN = /^did:[a-z]+:[a-zA-Z0-9._:-]+$/;
548
+ function person(options = {}) {
549
+ const isMultiple = options.multiple ?? false;
550
+ return {
551
+ definition: {
552
+ type: "person",
553
+ required: options.required ?? false,
554
+ config: {
555
+ multiple: isMultiple
556
+ }
557
+ },
558
+ validate(value) {
559
+ if (value === null || value === void 0) {
560
+ return !options.required;
561
+ }
562
+ if (isMultiple) {
563
+ if (!Array.isArray(value)) return false;
564
+ return value.every((v) => typeof v === "string" && DID_PATTERN.test(v));
565
+ } else {
566
+ return typeof value === "string" && DID_PATTERN.test(value);
567
+ }
568
+ },
569
+ coerce(value) {
570
+ if (value === null || value === void 0) {
571
+ return isMultiple ? [] : null;
572
+ }
573
+ if (isMultiple) {
574
+ const arr = Array.isArray(value) ? value : [value];
575
+ return arr.filter((v) => typeof v === "string" && DID_PATTERN.test(v));
576
+ } else {
577
+ if (typeof value === "string" && DID_PATTERN.test(value)) {
578
+ return value;
579
+ }
580
+ return null;
581
+ }
582
+ },
583
+ _type: isMultiple ? [] : ""
584
+ };
585
+ }
586
+
587
+ // src/schema/properties/relation.ts
588
+ function relation(options = {}) {
589
+ const isMultiple = options.multiple ?? false;
590
+ return {
591
+ definition: {
592
+ type: "relation",
593
+ required: options.required ?? false,
594
+ config: {
595
+ ...options.target !== void 0 && { target: options.target },
596
+ multiple: isMultiple
597
+ }
598
+ },
599
+ validate(value) {
600
+ if (value === null || value === void 0) {
601
+ return !options.required;
602
+ }
603
+ if (isMultiple) {
604
+ if (!Array.isArray(value)) return false;
605
+ return value.every((v) => typeof v === "string" && v.length > 0);
606
+ } else {
607
+ return typeof value === "string" && value.length > 0;
608
+ }
609
+ },
610
+ coerce(value) {
611
+ if (value === null || value === void 0) {
612
+ return isMultiple ? [] : null;
613
+ }
614
+ if (isMultiple) {
615
+ const arr = Array.isArray(value) ? value : [value];
616
+ return arr.filter((v) => typeof v === "string" && v.length > 0);
617
+ } else {
618
+ if (typeof value === "string" && value.length > 0) {
619
+ return value;
620
+ }
621
+ return null;
622
+ }
623
+ },
624
+ _type: isMultiple ? [] : ""
625
+ };
626
+ }
627
+
628
+ // src/schema/properties/url.ts
629
+ var URL_PATTERN = /^https?:\/\/.+/i;
630
+ function url(options = {}) {
631
+ return {
632
+ definition: {
633
+ type: "url",
634
+ required: options.required ?? false,
635
+ config: {
636
+ placeholder: options.placeholder
637
+ }
638
+ },
639
+ validate(value) {
640
+ if (value === null || value === void 0 || value === "") {
641
+ return !options.required;
642
+ }
643
+ if (typeof value !== "string") return false;
644
+ return URL_PATTERN.test(value);
645
+ },
646
+ coerce(value) {
647
+ if (value === null || value === void 0 || value === "") return null;
648
+ const str = String(value).trim();
649
+ if (str && !str.match(/^https?:\/\//i)) {
650
+ return `https://${str}`;
651
+ }
652
+ return str || null;
653
+ },
654
+ _type: ""
655
+ };
656
+ }
657
+
658
+ // src/schema/properties/email.ts
659
+ var EMAIL_PATTERN = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
660
+ function email(options = {}) {
661
+ return {
662
+ definition: {
663
+ type: "email",
664
+ required: options.required ?? false,
665
+ config: {
666
+ placeholder: options.placeholder
667
+ }
668
+ },
669
+ validate(value) {
670
+ if (value === null || value === void 0 || value === "") {
671
+ return !options.required;
672
+ }
673
+ if (typeof value !== "string") return false;
674
+ return EMAIL_PATTERN.test(value);
675
+ },
676
+ coerce(value) {
677
+ if (value === null || value === void 0 || value === "") return null;
678
+ const str = String(value).trim().toLowerCase();
679
+ return str || null;
680
+ },
681
+ _type: ""
682
+ };
683
+ }
684
+
685
+ // src/schema/properties/phone.ts
686
+ var PHONE_PATTERN = /^[+]?[(]?[0-9]{1,4}[)]?[-\s./0-9]*$/;
687
+ function phone(options = {}) {
688
+ return {
689
+ definition: {
690
+ type: "phone",
691
+ required: options.required ?? false,
692
+ config: {
693
+ placeholder: options.placeholder
694
+ }
695
+ },
696
+ validate(value) {
697
+ if (value === null || value === void 0 || value === "") {
698
+ return !options.required;
699
+ }
700
+ if (typeof value !== "string") return false;
701
+ const digitCount = value.replace(/\D/g, "").length;
702
+ return PHONE_PATTERN.test(value) && digitCount >= 7;
703
+ },
704
+ coerce(value) {
705
+ if (value === null || value === void 0 || value === "") return null;
706
+ const str = String(value).trim().replace(/\s+/g, " ");
707
+ return str || null;
708
+ },
709
+ _type: ""
710
+ };
711
+ }
712
+
713
+ // src/schema/properties/file.ts
714
+ function isValidFileRef(value) {
715
+ if (typeof value !== "object" || value === null) return false;
716
+ const obj = value;
717
+ return typeof obj.cid === "string" && typeof obj.name === "string" && typeof obj.mimeType === "string" && typeof obj.size === "number";
718
+ }
719
+ function file(options = {}) {
720
+ const isMultiple = options.multiple ?? false;
721
+ return {
722
+ definition: {
723
+ type: "file",
724
+ required: options.required ?? false,
725
+ config: {
726
+ multiple: isMultiple,
727
+ accept: options.accept,
728
+ maxSize: options.maxSize
729
+ }
730
+ },
731
+ validate(value) {
732
+ if (value === null || value === void 0) {
733
+ return !options.required;
734
+ }
735
+ if (isMultiple) {
736
+ if (!Array.isArray(value)) return false;
737
+ return value.every(isValidFileRef);
738
+ } else {
739
+ return isValidFileRef(value);
740
+ }
741
+ },
742
+ coerce(value) {
743
+ if (value === null || value === void 0) {
744
+ return isMultiple ? [] : null;
745
+ }
746
+ if (isMultiple) {
747
+ const arr = Array.isArray(value) ? value : [value];
748
+ return arr.filter(isValidFileRef);
749
+ } else {
750
+ if (isValidFileRef(value)) {
751
+ return value;
752
+ }
753
+ return null;
754
+ }
755
+ },
756
+ _type: isMultiple ? [] : {}
757
+ };
758
+ }
759
+
760
+ // src/schema/properties/created.ts
761
+ function created(options = {}) {
762
+ return {
763
+ definition: {
764
+ type: "created",
765
+ required: false,
766
+ // Auto-populated, not user-required
767
+ config: {
768
+ label: options.label,
769
+ auto: true,
770
+ readonly: true
771
+ }
772
+ },
773
+ validate(value) {
774
+ if (value === null || value === void 0) {
775
+ return true;
776
+ }
777
+ return typeof value === "number" && value > 0 && Number.isFinite(value);
778
+ },
779
+ coerce(value) {
780
+ if (value === null || value === void 0) {
781
+ return Date.now();
782
+ }
783
+ if (typeof value === "number" && value > 0) {
784
+ return value;
785
+ }
786
+ if (typeof value === "string") {
787
+ const parsed = Date.parse(value);
788
+ if (!isNaN(parsed)) return parsed;
789
+ }
790
+ return Date.now();
791
+ },
792
+ _type: 0
793
+ };
794
+ }
795
+
796
+ // src/schema/properties/updated.ts
797
+ function updated(options = {}) {
798
+ return {
799
+ definition: {
800
+ type: "updated",
801
+ required: false,
802
+ // Auto-populated, not user-required
803
+ config: {
804
+ label: options.label,
805
+ auto: true,
806
+ readonly: true
807
+ }
808
+ },
809
+ validate(value) {
810
+ if (value === null || value === void 0) {
811
+ return true;
812
+ }
813
+ return typeof value === "number" && value > 0 && Number.isFinite(value);
814
+ },
815
+ coerce(value) {
816
+ if (value === null || value === void 0) {
817
+ return Date.now();
818
+ }
819
+ if (typeof value === "number" && value > 0) {
820
+ return value;
821
+ }
822
+ if (typeof value === "string") {
823
+ const parsed = Date.parse(value);
824
+ if (!isNaN(parsed)) return parsed;
825
+ }
826
+ return Date.now();
827
+ },
828
+ _type: 0
829
+ };
830
+ }
831
+
832
+ // src/schema/properties/createdBy.ts
833
+ var DID_PATTERN2 = /^did:[a-z]+:[a-zA-Z0-9._:-]+$/;
834
+ function createdBy(options = {}) {
835
+ return {
836
+ definition: {
837
+ type: "createdBy",
838
+ required: false,
839
+ // Auto-populated, not user-required
840
+ config: {
841
+ label: options.label,
842
+ auto: true,
843
+ readonly: true
844
+ }
845
+ },
846
+ validate(value) {
847
+ if (value === null || value === void 0) {
848
+ return true;
849
+ }
850
+ return typeof value === "string" && DID_PATTERN2.test(value);
851
+ },
852
+ coerce(value) {
853
+ if (value === null || value === void 0) {
854
+ return null;
855
+ }
856
+ if (typeof value === "string" && DID_PATTERN2.test(value)) {
857
+ return value;
858
+ }
859
+ return null;
860
+ },
861
+ _type: ""
862
+ };
863
+ }
864
+
865
+ export {
866
+ DEFAULT_SCHEMA_VERSION,
867
+ parseSchemaIRI,
868
+ buildSchemaIRI,
869
+ normalizeSchemaIRI,
870
+ getBaseSchemaIRI,
871
+ isSameSchema,
872
+ getSchemaVersion,
873
+ isNode,
874
+ createNodeId,
875
+ DEFAULT_SCHEMA_VERSION2,
876
+ defineSchema,
877
+ text,
878
+ number,
879
+ checkbox,
880
+ json,
881
+ isMoneyValue,
882
+ money,
883
+ date,
884
+ dateRange,
885
+ select,
886
+ multiSelect,
887
+ person,
888
+ relation,
889
+ url,
890
+ email,
891
+ phone,
892
+ file,
893
+ created,
894
+ updated,
895
+ createdBy
896
+ };