soukai-bis 0.0.0-next.644ab9a2b8f38acac0b1af7fdd2c32dac992efb8 → 0.0.0-next.6ae0e13a5d51cb0b555c0f6a877b441cf081731e

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.
@@ -1,11 +1,25 @@
1
1
  import { Constructor } from '@noeldemartin/utils';
2
+ import { Fetch } from '@noeldemartin/solid-utils';
3
+ import { JSError } from '@noeldemartin/utils';
4
+ import { JSErrorOptions } from '@noeldemartin/utils';
2
5
  import { JsonLD } from '@noeldemartin/solid-utils';
3
6
  import { MagicObject } from '@noeldemartin/utils';
4
7
  import { NamedNode } from '@rdfjs/types';
8
+ import { Override } from '@noeldemartin/utils';
5
9
  import { z } from 'zod';
6
10
  import { ZodObject } from 'zod';
7
11
  import { ZodType } from 'zod';
8
12
 
13
+ export declare type BootedModelClass<T extends typeof Model> = T & {
14
+ _collection: string;
15
+ _modelName: string;
16
+ };
17
+
18
+ export declare function bootModels(models: Record<string, {
19
+ boot(name: string): unknown;
20
+ reset(): void;
21
+ }>, reset?: boolean): void;
22
+
9
23
  declare namespace coreExtensions {
10
24
  export {
11
25
  rdfProperty,
@@ -17,27 +31,102 @@ declare interface CustomMeta {
17
31
  rdfProperty?: string;
18
32
  }
19
33
 
20
- export declare function defineSchema<T extends SchemaFields>(config: SchemaConfig<T>): SchemaModel<T>;
34
+ export declare function defineSchema<T extends SchemaFields>(config: SchemaConfig<T>): SchemaModelClass<T>;
35
+
36
+ export declare class DocumentAlreadyExists extends SoukaiError {
37
+ readonly url: string;
38
+ constructor(url: string);
39
+ }
40
+
41
+ export declare interface Engine {
42
+ createDocument(url: string, graph: JsonLD): Promise<void>;
43
+ updateDocument(url: string, graph: JsonLD, dirtyAttributes?: string[]): Promise<void>;
44
+ readManyDocuments(containerUrl: string): Promise<Record<string, JsonLD>>;
45
+ }
46
+
47
+ export declare function getEngine(): Engine | undefined;
21
48
 
22
- export declare class Model extends MagicObject {
49
+ export declare class IndexedDBEngine implements Engine {
50
+ private database;
51
+ private metadataConnection;
52
+ private documentsConnection;
53
+ private lock;
54
+ constructor(database?: string);
55
+ close(): Promise<void>;
56
+ createDocument(url: string, graph: JsonLD): Promise<void>;
57
+ updateDocument(url: string, graph: JsonLD): Promise<void>;
58
+ readManyDocuments(containerUrl: string): Promise<Record<string, JsonLD>>;
59
+ private createCollection;
60
+ private collectionExists;
61
+ private getCollections;
62
+ private withMetadataTransaction;
63
+ private withDocumentsTransaction;
64
+ private getMetadataConnection;
65
+ private getDocumentsConnection;
66
+ }
67
+
68
+ export declare class InMemoryEngine implements Engine {
69
+ documents: Record<string, JsonLD>;
70
+ createDocument(url: string, graph: JsonLD): Promise<void>;
71
+ updateDocument(url: string, graph: JsonLD): Promise<void>;
72
+ readManyDocuments(containerUrl: string): Promise<Record<string, JsonLD>>;
73
+ }
74
+
75
+ export declare type MintedModel<T> = T & {
76
+ url: string;
77
+ };
78
+
79
+ export declare class Model<Attributes extends Record<string, unknown> = Record<string, unknown>, Field extends string = Exclude<keyof Attributes, number | symbol>> extends MagicObject {
23
80
  static schema: Schema;
81
+ protected static _collection?: string;
82
+ protected static _modelName?: string;
83
+ private static __booted;
84
+ static get collection(): string;
85
+ static get modelName(): string;
86
+ static boot<T extends typeof Model>(this: T, name?: string): void;
87
+ static reset(): void;
88
+ static newInstance<T extends Model>(this: ModelConstructor<T>, ...params: ConstructorParameters<ModelConstructor<T>>): T;
89
+ static all<T extends Model>(this: ModelConstructor<T>, containerUrl: string): Promise<MintedModel<T>[]>;
90
+ static create<T extends Model>(this: ModelConstructor<T>, ...args: ConstructorParameters<ModelConstructor<T>>): Promise<MintedModel<T>>;
91
+ static createFromJsonLD<T extends Model>(this: ModelConstructor<T>, json: JsonLD, options?: {
92
+ url?: string;
93
+ }): Promise<MintedModel<T> | null>;
24
94
  static<T extends typeof Model>(): T;
25
95
  static<T extends typeof Model, K extends keyof T>(property: K): T[K];
96
+ private static booted;
26
97
  url?: string;
98
+ private __exists;
27
99
  private __attributes;
28
- constructor(attributes?: Record<string, unknown>);
29
- getAttributes(): Record<string, unknown>;
100
+ private __dirtyAttributes;
101
+ constructor(attributes?: Record<string, unknown>, exists?: boolean);
102
+ getAttributes(): Attributes;
103
+ isDirty(field?: Field): boolean;
104
+ exists(): boolean;
105
+ setExists(exists: boolean): void;
106
+ save(): Promise<MintedModel<this>>;
107
+ update(attributes: Partial<Attributes>): Promise<MintedModel<this>>;
30
108
  toJsonLD(): Promise<JsonLD>;
31
109
  toTurtle(): Promise<string>;
32
110
  protected __get(property: string): unknown;
111
+ protected __set(property: string, value: unknown): void;
112
+ protected mintUrl(): string;
113
+ private parseAttribute;
114
+ private parseAttributes;
115
+ private isField;
33
116
  }
34
117
 
118
+ export declare type ModelConstructor<T extends Model = Model> = Constructor<T> & Omit<typeof Model, 'new'>;
119
+
120
+ export declare type ModelInstanceType<T> = T extends Constructor<infer TInstance> ? TInstance : never;
121
+
35
122
  export declare function patchZod(): void;
36
123
 
37
124
  declare function rdfProperty<T extends ZodType>(this: T): string | undefined;
38
125
 
39
126
  declare function rdfProperty<T extends ZodType>(this: T, value: string): T;
40
127
 
128
+ export declare function requireEngine(): Engine;
129
+
41
130
  export declare type Schema<T extends SchemaFields = SchemaFields> = {
42
131
  fields: ZodObject<T>;
43
132
  rdfContext: {
@@ -45,7 +134,7 @@ export declare type Schema<T extends SchemaFields = SchemaFields> = {
45
134
  } & Record<string, string>;
46
135
  rdfClasses: NamedNode[];
47
136
  rdfDefaultResourceHash: string;
48
- rdfFieldProperties: Record<string, NamedNode>;
137
+ rdfFieldProperties: Record<keyof T, NamedNode>;
49
138
  };
50
139
 
51
140
  export declare interface SchemaConfig<T extends SchemaFields> {
@@ -59,7 +148,38 @@ export declare interface SchemaConfig<T extends SchemaFields> {
59
148
 
60
149
  export declare type SchemaFields = Record<string, ZodType>;
61
150
 
62
- export declare type SchemaModel<T extends SchemaFields> = typeof Model & Constructor<z.infer<ZodObject<T>>>;
151
+ export declare type SchemaModel<T extends SchemaFields = SchemaFields> = Model<SchemaModelAttributes<T>> & z.infer<ZodObject<T>>;
152
+
153
+ export declare type SchemaModelAttributes<T extends SchemaFields = SchemaFields> = z.infer<ZodObject<T>> & {
154
+ url?: string;
155
+ };
156
+
157
+ export declare type SchemaModelClass<T extends SchemaFields = SchemaFields> = Override<typeof Model, {
158
+ new (attributes?: SchemaModelInput<T>, exists?: boolean): SchemaModel<T>;
159
+ newInstance<This>(this: This, attributes?: SchemaModelInput<T>, exists?: boolean): ModelInstanceType<This>;
160
+ create<This>(this: This, attributes?: SchemaModelInput<T>): Promise<MintedModel<ModelInstanceType<This>>>;
161
+ createFromJsonLD<This>(this: This, json: JsonLD, options?: {
162
+ url?: string;
163
+ }): Promise<MintedModel<ModelInstanceType<This>> | null>;
164
+ }>;
165
+
166
+ export declare type SchemaModelInput<T extends SchemaFields = SchemaFields> = z.input<ZodObject<T>> & {
167
+ url?: string;
168
+ };
169
+
170
+ export declare function setEngine(engine: Engine): void;
171
+
172
+ export declare class SolidEngine implements Engine {
173
+ private client;
174
+ constructor(fetch?: Fetch);
175
+ createDocument(url: string, graph: JsonLD): Promise<void>;
176
+ updateDocument(url: string, graph: JsonLD, dirtyProperties?: string[]): Promise<void>;
177
+ readManyDocuments(containerUrl: string): Promise<Record<string, JsonLD>>;
178
+ }
179
+
180
+ export declare class SoukaiError extends JSError {
181
+ constructor(message?: string, options?: JSErrorOptions);
182
+ }
63
183
 
64
184
  export declare type ZodCoreExtensions = typeof coreExtensions;
65
185
 
@@ -1,103 +1,368 @@
1
- var j = Object.defineProperty;
2
- var x = (t, r, e) => r in t ? j(t, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[r] = e;
3
- var f = (t, r, e) => x(t, typeof r != "symbol" ? r + "" : r, e);
4
- import { ZodArray as C, ZodURL as R, ZodOptional as m, ZodDefault as b, object as P, z as F } from "zod";
5
- import { MagicObject as O } from "@noeldemartin/utils";
6
- import { expandIRI as c, RDFNamedNode as u, RDFQuad as p, RDFLiteral as w, quadsToJsonLD as g, quadsToTurtle as Z } from "@noeldemartin/solid-utils";
7
- const A = c("rdf:type");
8
- function d(t) {
9
- return t instanceof m || t instanceof b ? d(t.def.innerType) : t;
10
- }
11
- function _(t, r) {
12
- const e = d(r);
13
- return e instanceof C ? (Array.isArray(t) ? t : t == null ? [] : [t]).flatMap((s) => _(s, e.def.element)) : e instanceof R ? [new u(String(t))] : [new w(String(t))];
14
- }
15
- function h(t) {
16
- const { fields: r, rdfDefaultResourceHash: e, rdfClasses: n, rdfFieldProperties: s } = t.static().schema, i = new u(t.url ?? `#${e}`), o = [];
17
- for (const a of n)
18
- o.push(new p(i, A, a));
19
- for (const [a, y] of Object.entries(t.getAttributes()))
20
- for (const D of _(y, r.def.shape[a]))
21
- o.push(new p(i, s[a], D));
1
+ var J = Object.defineProperty;
2
+ var Z = (n, e, t) => e in n ? J(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
+ var c = (n, e, t) => Z(n, typeof e != "symbol" ? e + "" : e, t);
4
+ import { ZodOptional as P, ZodDefault as R, ZodArray as I, ZodNumber as q, ZodURL as z, object as B, url as Q, z as U } from "zod";
5
+ import { JSError as V, fail as L, required as H, MagicObject as W, stringToCamelCase as A, objectOnly as Y, uuid as G, Semaphore as K, requireUrlParentDirectory as E, reduceBy as X } from "@noeldemartin/utils";
6
+ import { expandIRI as h, RDFNamedNode as f, SolidStore as tt, RDFQuad as O, RDFLiteral as et, jsonldToQuads as C, quadsToJsonLD as M, quadsToTurtle as m, SolidClient as nt } from "@noeldemartin/solid-utils";
7
+ import { openDB as N } from "idb";
8
+ function mt(n, e = !1) {
9
+ for (const [t, s] of Object.entries(n))
10
+ e && s.reset(), s.boot(t);
11
+ }
12
+ class T extends V {
13
+ constructor(e, t) {
14
+ super(e, t);
15
+ }
16
+ }
17
+ let j;
18
+ function _t(n) {
19
+ j = n;
20
+ }
21
+ function bt() {
22
+ return j;
23
+ }
24
+ function D() {
25
+ return j ?? L(T, "Default engine hasn't been initialized");
26
+ }
27
+ const st = h("ldp:BasicContainer"), it = h("ldp:Container"), at = h("ldp:contains"), p = h("rdf:type");
28
+ function b(n) {
29
+ return n instanceof P || n instanceof R ? b(n.def.innerType) : n;
30
+ }
31
+ function S(n, e) {
32
+ return e instanceof q ? Number(n) : n;
33
+ }
34
+ function ot(n, e, t) {
35
+ const { fields: s, rdfFieldProperties: i } = n.schema, a = new f(e), o = {}, r = new tt(t);
36
+ for (const [d, u] of Object.entries(s.shape)) {
37
+ const l = b(u), w = i[d], y = r.statements(a, w);
38
+ if (!(!w || y.length === 0)) {
39
+ if (l instanceof I) {
40
+ const $ = b(l.element);
41
+ o[d] = y.map((k) => S(k.object.value, $));
42
+ continue;
43
+ }
44
+ o[d] = S(H(y[0]).object.value, l);
45
+ }
46
+ }
47
+ return n.newInstance({ url: e, ...o }, !0);
48
+ }
49
+ function v(n, e) {
50
+ const t = b(e);
51
+ return t instanceof I ? (Array.isArray(n) ? n : n == null ? [] : [n]).flatMap((i) => v(i, t.def.element)) : t instanceof z ? [new f(String(n))] : [new et(String(n))];
52
+ }
53
+ function F(n) {
54
+ const { fields: e, rdfDefaultResourceHash: t, rdfClasses: s, rdfFieldProperties: i } = n.static().schema, a = new f(n.url ?? `#${t}`), o = [];
55
+ for (const r of s)
56
+ o.push(new O(a, p, r));
57
+ for (const [r, d] of Object.entries(n.getAttributes())) {
58
+ const u = e.def.shape[r], l = i[r];
59
+ if (!(!u || !l))
60
+ for (const w of v(d, u))
61
+ o.push(new O(a, l, w));
62
+ }
22
63
  return o;
23
64
  }
24
- class T extends O {
25
- constructor(e = {}) {
65
+ class _ extends W {
66
+ constructor(t = {}, s = !1) {
26
67
  super();
27
- f(this, "__attributes");
68
+ c(this, "__exists", !1);
69
+ c(this, "__attributes");
70
+ c(this, "__dirtyAttributes", /* @__PURE__ */ new Set());
28
71
  if (this.static().isConjuring()) {
29
72
  this.__attributes = {};
30
73
  return;
31
74
  }
32
- this.__attributes = this.static().schema.fields.parse(e);
75
+ this.__exists = s, this.__attributes = this.parseAttributes(t);
76
+ }
77
+ static get collection() {
78
+ return this._collection ?? this.booted()._collection;
79
+ }
80
+ static get modelName() {
81
+ return this._modelName ?? this.booted()._modelName;
82
+ }
83
+ static boot(t) {
84
+ if (this.__booted)
85
+ throw new T(`${this.name} model already booted`);
86
+ this._modelName ?? (this._modelName = t ?? this.name), this._collection ?? (this._collection = `solid://${A(this._modelName)}s/`), this.__booted = !0;
33
87
  }
34
- static(e) {
35
- return super.static(e);
88
+ static reset() {
89
+ this.__booted = !1;
90
+ }
91
+ static newInstance(...t) {
92
+ return new this(...t);
93
+ }
94
+ static async all(t) {
95
+ const i = await D().readManyDocuments(t);
96
+ return (await Promise.all(
97
+ Object.entries(i).map(([o, r]) => this.createFromJsonLD(r, { url: o }))
98
+ )).filter((o) => o !== null);
99
+ }
100
+ static async create(...t) {
101
+ return new this(...t).save();
102
+ }
103
+ static async createFromJsonLD(t, s = {}) {
104
+ const i = s.url ?? t["@id"] ?? L("JsonLD is missing @id"), a = await C(t), o = new f(i), r = (d) => a.some(
105
+ (u) => u.subject.value === o.value && u.predicate.value === p && u.object.value === d.value
106
+ );
107
+ return this.schema.rdfClasses.some(r) ? ot(this, i, a) : null;
108
+ }
109
+ static(t) {
110
+ return super.static(t);
111
+ }
112
+ static booted() {
113
+ return this.__booted || (this._modelName ?? (this._modelName = this.name), this._collection ?? (this._collection = `solid://${A(this._modelName)}s/`), this.__booted = !0), this;
36
114
  }
37
115
  getAttributes() {
38
116
  return this.__attributes;
39
117
  }
118
+ isDirty(t) {
119
+ return t ? this.__dirtyAttributes.has(t) : this.__dirtyAttributes.size > 0;
120
+ }
121
+ exists() {
122
+ return this.__exists;
123
+ }
124
+ setExists(t) {
125
+ this.__exists = t;
126
+ }
127
+ async save() {
128
+ this.url ?? (this.url = this.mintUrl());
129
+ const t = await this.toJsonLD();
130
+ if (this.__exists) {
131
+ const s = Array.from(this.__dirtyAttributes).map((i) => {
132
+ var a;
133
+ return (a = this.static().schema.rdfFieldProperties[i]) == null ? void 0 : a.value;
134
+ }).filter((i) => !!i);
135
+ await D().updateDocument(this.url, t, s);
136
+ } else
137
+ await D().createDocument(this.url, t), this.__exists = !0;
138
+ return this.__dirtyAttributes.clear(), this;
139
+ }
140
+ update(t) {
141
+ const s = Y(this.static().schema.fields.def.shape, Object.keys(t)), i = Object.fromEntries(
142
+ Object.entries(s).map(([a, o]) => [a, o.parse(t[a])])
143
+ );
144
+ return Object.assign(this.__attributes, i), Object.keys(i).forEach((a) => this.__dirtyAttributes.add(a)), this.save();
145
+ }
40
146
  async toJsonLD() {
41
- return g(h(this));
147
+ return M(F(this));
42
148
  }
43
149
  async toTurtle() {
44
- return Z(h(this));
45
- }
46
- __get(e) {
47
- return this.__attributes[e];
48
- }
49
- }
50
- f(T, "schema");
51
- function V(t) {
52
- var s;
53
- const r = t.rdfContext ? { default: t.rdfContext } : { default: "solid" }, { default: e, ...n } = r;
54
- return s = class extends T {
55
- }, f(s, "schema", {
56
- fields: P(t.fields),
57
- rdfContext: r,
58
- rdfDefaultResourceHash: t.rdfDefaultResourceHash ?? "it",
59
- rdfClasses: t.rdfClass ? [
60
- new u(
61
- c(t.rdfClass, {
62
- defaultPrefix: e,
63
- extraContext: n
150
+ return m(F(this));
151
+ }
152
+ __get(t) {
153
+ return this.__attributes[t];
154
+ }
155
+ __set(t, s) {
156
+ this.isField(t) && (this.__attributes[t] = this.parseAttribute(t, s), this.__dirtyAttributes.add(t));
157
+ }
158
+ mintUrl() {
159
+ return `${this.static().collection}${G()}`;
160
+ }
161
+ parseAttribute(t, s) {
162
+ var i;
163
+ return (i = this.static().schema.fields.def.shape[t]) == null ? void 0 : i.parse(s);
164
+ }
165
+ parseAttributes(t) {
166
+ return this.static().schema.fields.parse(t);
167
+ }
168
+ isField(t) {
169
+ return t in this.static().schema.fields.def.shape;
170
+ }
171
+ }
172
+ c(_, "schema"), c(_, "_collection"), c(_, "_modelName"), c(_, "__booted", !1);
173
+ function wt(n) {
174
+ var i;
175
+ const e = n.rdfContext ? { default: n.rdfContext } : { default: "solid" }, { default: t, ...s } = e;
176
+ return i = class extends _ {
177
+ }, c(i, "schema", {
178
+ fields: B(n.fields).extend({ url: Q().optional() }),
179
+ rdfContext: e,
180
+ rdfDefaultResourceHash: n.rdfDefaultResourceHash ?? "it",
181
+ rdfClasses: n.rdfClass ? [
182
+ new f(
183
+ h(n.rdfClass, {
184
+ defaultPrefix: t,
185
+ extraContext: s
64
186
  })
65
187
  )
66
188
  ] : [],
67
189
  rdfFieldProperties: Object.fromEntries(
68
- Object.entries(t.fields).map(([i, o]) => [
69
- i,
70
- new u(
71
- c(o.rdfProperty() ?? i, {
72
- defaultPrefix: e,
73
- extraContext: n
190
+ Object.entries(n.fields).map(([a, o]) => [
191
+ a,
192
+ new f(
193
+ h(o.rdfProperty() ?? a, {
194
+ defaultPrefix: t,
195
+ extraContext: s
74
196
  })
75
197
  )
76
198
  ])
77
199
  )
78
- }), s;
200
+ }), i;
201
+ }
202
+ class x extends T {
203
+ constructor(t) {
204
+ super(`Could not create document with url '${t}' because it is already in use.`);
205
+ c(this, "url");
206
+ this.url = t;
207
+ }
208
+ }
209
+ class pt {
210
+ constructor(e = "soukai-bis") {
211
+ c(this, "database");
212
+ c(this, "metadataConnection", null);
213
+ c(this, "documentsConnection", null);
214
+ c(this, "lock");
215
+ this.database = e, this.lock = new K();
216
+ }
217
+ async close() {
218
+ this.metadataConnection && ((await this.metadataConnection).close(), this.metadataConnection = null), this.documentsConnection && ((await this.documentsConnection).close(), this.documentsConnection = null);
219
+ }
220
+ async createDocument(e, t) {
221
+ await this.lock.run(async () => {
222
+ const s = E(e);
223
+ await this.withDocumentsTransaction(s, "readwrite", async (i) => {
224
+ if (await i.store.get(e))
225
+ throw new x(e);
226
+ return i.store.add({ url: e, graph: t });
227
+ });
228
+ });
229
+ }
230
+ async updateDocument(e, t) {
231
+ await this.lock.run(async () => {
232
+ const s = E(e);
233
+ await this.collectionExists(s) && await this.withDocumentsTransaction(s, "readwrite", (i) => i.store.put({ url: e, graph: t }));
234
+ });
235
+ }
236
+ async readManyDocuments(e) {
237
+ return this.lock.run(async () => {
238
+ if (!await this.collectionExists(e))
239
+ return {};
240
+ const t = await this.withDocumentsTransaction(e, "readonly", (s) => s.store.getAll());
241
+ return X(t, "url", (s) => s.graph);
242
+ });
243
+ }
244
+ async createCollection(e) {
245
+ await this.collectionExists(e) || await this.withMetadataTransaction("readwrite", (t) => t.store.add({ name: e }));
246
+ }
247
+ async collectionExists(e) {
248
+ return (await this.getCollections()).includes(e);
249
+ }
250
+ async getCollections() {
251
+ return (await this.withMetadataTransaction("readonly", (t) => t.store.getAll())).map((t) => t.name);
252
+ }
253
+ async withMetadataTransaction(e, t) {
254
+ const i = (await this.getMetadataConnection()).transaction("collections", e);
255
+ return t(i);
256
+ }
257
+ async withDocumentsTransaction(e, t, s) {
258
+ t === "readwrite" && !await this.collectionExists(e) && await this.createCollection(e);
259
+ const a = (await this.getDocumentsConnection()).transaction(e, t);
260
+ return s(a);
261
+ }
262
+ async getMetadataConnection() {
263
+ return this.metadataConnection ? this.metadataConnection : this.metadataConnection = N(`${this.database}-meta`, 1, {
264
+ upgrade(e) {
265
+ e.objectStoreNames.contains("collections") || e.createObjectStore("collections", { keyPath: "name" });
266
+ }
267
+ });
268
+ }
269
+ async getDocumentsConnection() {
270
+ if (this.documentsConnection)
271
+ return this.documentsConnection;
272
+ const e = await this.getCollections();
273
+ return this.documentsConnection = N(this.database, e.length + 1, {
274
+ upgrade(t) {
275
+ for (const s of e)
276
+ t.objectStoreNames.contains(s) || t.createObjectStore(s, { keyPath: "url" });
277
+ }
278
+ });
279
+ }
280
+ }
281
+ class yt {
282
+ constructor() {
283
+ c(this, "documents", {});
284
+ }
285
+ async createDocument(e, t) {
286
+ if (e in this.documents)
287
+ throw new x(e);
288
+ this.documents[e] = t;
289
+ }
290
+ async updateDocument(e, t) {
291
+ this.documents[e] = t;
292
+ }
293
+ async readManyDocuments(e) {
294
+ const t = {};
295
+ for (const [s, i] of Object.entries(this.documents))
296
+ s.startsWith(e) && (t[s] = i);
297
+ return t;
298
+ }
299
+ }
300
+ class Dt {
301
+ constructor(e) {
302
+ c(this, "client");
303
+ this.client = new nt({ fetch: e });
304
+ }
305
+ async createDocument(e, t) {
306
+ if (await this.client.exists(e))
307
+ throw new x(e);
308
+ const s = await C(t), i = m(s);
309
+ await this.client.create(e, i);
310
+ }
311
+ async updateDocument(e, t, s) {
312
+ const i = await C(t);
313
+ if (s && s.length > 0) {
314
+ const o = await this.client.read(e), r = i.filter((u) => s.includes(u.predicate.value)), d = o.statements().filter((u) => s.includes(u.predicate.value));
315
+ await this.client.update(
316
+ e,
317
+ `
318
+ DELETE DATA { ${m(d)} } ;
319
+ INSERT DATA { ${m(r)} }
320
+ `
321
+ );
322
+ }
323
+ const a = m(i);
324
+ await this.client.create(e, a);
325
+ }
326
+ async readManyDocuments(e) {
327
+ const s = (await this.client.read(e)).statements(e, at), i = {};
328
+ return await Promise.all(
329
+ s.map(async (a) => {
330
+ const o = a.object.value, r = await this.client.readIfFound(o);
331
+ !r || r.contains(o, p, it) || r.contains(o, p, st) || (i[o] = await M(r.getQuads()));
332
+ })
333
+ ), i;
334
+ }
79
335
  }
80
- function l(t, r) {
81
- const e = t.meta();
82
- if (e && r in e)
83
- return e[r];
84
- if (t instanceof b || t instanceof m)
85
- return l(t.def.innerType, r);
336
+ function g(n, e) {
337
+ const t = n.meta();
338
+ if (t && e in t)
339
+ return t[e];
340
+ if (n instanceof R || n instanceof P)
341
+ return g(n.def.innerType, e);
86
342
  }
87
- function S(t) {
88
- return typeof t != "string" ? l(this, "rdfProperty") : this.meta({ rdfProperty: t });
343
+ function rt(n) {
344
+ return typeof n != "string" ? g(this, "rdfProperty") : this.meta({ rdfProperty: n });
89
345
  }
90
- const L = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
346
+ const ct = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
91
347
  __proto__: null,
92
- rdfProperty: S
348
+ rdfProperty: rt
93
349
  }, Symbol.toStringTag, { value: "Module" }));
94
- function q() {
95
- for (const [t, r] of Object.entries(L))
96
- F.ZodType.prototype[t] = r;
350
+ function Ct() {
351
+ for (const [n, e] of Object.entries(ct))
352
+ U.ZodType.prototype[n] = e;
97
353
  }
98
354
  export {
99
- T as Model,
100
- V as defineSchema,
101
- q as patchZod
355
+ x as DocumentAlreadyExists,
356
+ yt as InMemoryEngine,
357
+ pt as IndexedDBEngine,
358
+ _ as Model,
359
+ Dt as SolidEngine,
360
+ T as SoukaiError,
361
+ mt as bootModels,
362
+ wt as defineSchema,
363
+ bt as getEngine,
364
+ Ct as patchZod,
365
+ D as requireEngine,
366
+ _t as setEngine
102
367
  };
103
368
  //# sourceMappingURL=soukai-bis.js.map