soukai-bis 0.0.0-next.644ab9a2b8f38acac0b1af7fdd2c32dac992efb8 → 0.0.0-next.f91035aead5d66e83db383d8022a10f851222e7d
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/soukai-bis.d.ts +86 -3
- package/dist/soukai-bis.js +247 -73
- package/dist/soukai-bis.js.map +1 -1
- package/package.json +10 -3
- package/src/engines/Engine.ts +7 -0
- package/src/engines/InMemoryEngine.ts +35 -0
- package/src/engines/IndexedDBEngine.test.ts +208 -0
- package/src/engines/IndexedDBEngine.ts +183 -0
- package/src/engines/index.ts +4 -0
- package/src/engines/state.ts +16 -0
- package/src/index.ts +1 -0
- package/src/models/Model.test.ts +104 -1
- package/src/models/Model.ts +123 -4
- package/src/models/concerns/creates-from-rdf.ts +49 -0
- package/src/models/concerns/serializes-to-rdf.ts +2 -13
- package/src/models/helpers.ts +10 -0
- package/src/models/index.ts +3 -1
- package/src/models/schema.ts +8 -5
- package/src/models/types.ts +5 -0
- package/src/zod/utils.ts +14 -0
package/dist/soukai-bis.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Constructor } from '@noeldemartin/utils';
|
|
2
1
|
import { JsonLD } from '@noeldemartin/solid-utils';
|
|
3
2
|
import { MagicObject } from '@noeldemartin/utils';
|
|
4
3
|
import { NamedNode } from '@rdfjs/types';
|
|
@@ -6,6 +5,16 @@ import { z } from 'zod';
|
|
|
6
5
|
import { ZodObject } from 'zod';
|
|
7
6
|
import { ZodType } from 'zod';
|
|
8
7
|
|
|
8
|
+
export declare type BootedModelClass<T extends typeof Model> = T & {
|
|
9
|
+
_collection: string;
|
|
10
|
+
_modelName: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export declare function bootModels(models: Record<string, {
|
|
14
|
+
boot(name: string): unknown;
|
|
15
|
+
reset(): void;
|
|
16
|
+
}>, reset?: boolean): void;
|
|
17
|
+
|
|
9
18
|
declare namespace coreExtensions {
|
|
10
19
|
export {
|
|
11
20
|
rdfProperty,
|
|
@@ -19,25 +28,93 @@ declare interface CustomMeta {
|
|
|
19
28
|
|
|
20
29
|
export declare function defineSchema<T extends SchemaFields>(config: SchemaConfig<T>): SchemaModel<T>;
|
|
21
30
|
|
|
31
|
+
export declare interface Engine {
|
|
32
|
+
createDocument(url: string, graph: JsonLD): Promise<void>;
|
|
33
|
+
updateDocument(url: string, graph: JsonLD): Promise<void>;
|
|
34
|
+
readManyDocuments(containerUrl: string): Promise<Record<string, JsonLD>>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export declare function getEngine(): Engine | undefined;
|
|
38
|
+
|
|
39
|
+
export declare class IndexedDBEngine implements Engine {
|
|
40
|
+
private database;
|
|
41
|
+
private metadataConnection;
|
|
42
|
+
private documentsConnection;
|
|
43
|
+
private lock;
|
|
44
|
+
constructor(database?: string);
|
|
45
|
+
close(): Promise<void>;
|
|
46
|
+
createDocument(url: string, graph: JsonLD): Promise<void>;
|
|
47
|
+
updateDocument(url: string, graph: JsonLD): Promise<void>;
|
|
48
|
+
readManyDocuments(containerUrl: string): Promise<Record<string, JsonLD>>;
|
|
49
|
+
private createCollection;
|
|
50
|
+
private collectionExists;
|
|
51
|
+
private getCollections;
|
|
52
|
+
private withMetadataTransaction;
|
|
53
|
+
private withDocumentsTransaction;
|
|
54
|
+
private getMetadataConnection;
|
|
55
|
+
private getDocumentsConnection;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export declare class InMemoryEngine implements Engine {
|
|
59
|
+
documents: Record<string, JsonLD>;
|
|
60
|
+
createDocument(url: string, graph: JsonLD): Promise<void>;
|
|
61
|
+
updateDocument(url: string, graph: JsonLD): Promise<void>;
|
|
62
|
+
readManyDocuments(containerUrl: string): Promise<Record<string, JsonLD>>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export declare interface LocalDocument {
|
|
66
|
+
url: string;
|
|
67
|
+
graph: JsonLD;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export declare type MintedModel<T extends Model> = T & {
|
|
71
|
+
url: string;
|
|
72
|
+
};
|
|
73
|
+
|
|
22
74
|
export declare class Model extends MagicObject {
|
|
23
75
|
static schema: Schema;
|
|
76
|
+
protected static _collection?: string;
|
|
77
|
+
protected static _modelName?: string;
|
|
78
|
+
private static __booted;
|
|
79
|
+
static get collection(): string;
|
|
80
|
+
static get modelName(): string;
|
|
81
|
+
static boot<T extends typeof Model>(this: T, name?: string): void;
|
|
82
|
+
static reset(): void;
|
|
83
|
+
static newInstance<T extends Model>(this: ModelConstructor<T>, ...params: ConstructorParameters<ModelConstructor<T>>): T;
|
|
84
|
+
static all<T extends Model>(this: ModelConstructor<T>, containerUrl: string): Promise<MintedModel<T>[]>;
|
|
85
|
+
static create<T extends Model>(this: ModelConstructor<T>, ...args: ConstructorParameters<ModelConstructor<T>>): Promise<MintedModel<T>>;
|
|
86
|
+
static createFromJsonLD<T extends Model>(this: ModelConstructor<T>, json: JsonLD, options?: {
|
|
87
|
+
url?: string;
|
|
88
|
+
}): Promise<MintedModel<T> | null>;
|
|
24
89
|
static<T extends typeof Model>(): T;
|
|
25
90
|
static<T extends typeof Model, K extends keyof T>(property: K): T[K];
|
|
91
|
+
private static booted;
|
|
26
92
|
url?: string;
|
|
93
|
+
private __exists;
|
|
27
94
|
private __attributes;
|
|
28
|
-
constructor(attributes?: Record<string, unknown
|
|
95
|
+
constructor(attributes?: Record<string, unknown>, exists?: boolean);
|
|
29
96
|
getAttributes(): Record<string, unknown>;
|
|
97
|
+
exists(): boolean;
|
|
98
|
+
setExists(exists: boolean): void;
|
|
99
|
+
save(): Promise<MintedModel<this>>;
|
|
30
100
|
toJsonLD(): Promise<JsonLD>;
|
|
31
101
|
toTurtle(): Promise<string>;
|
|
32
102
|
protected __get(property: string): unknown;
|
|
103
|
+
protected mintUrl(): string;
|
|
33
104
|
}
|
|
34
105
|
|
|
106
|
+
export declare type ModelConstructor<T extends Model = Model> = {
|
|
107
|
+
new (...args: any[]): T;
|
|
108
|
+
} & Omit<typeof Model, 'new'>;
|
|
109
|
+
|
|
35
110
|
export declare function patchZod(): void;
|
|
36
111
|
|
|
37
112
|
declare function rdfProperty<T extends ZodType>(this: T): string | undefined;
|
|
38
113
|
|
|
39
114
|
declare function rdfProperty<T extends ZodType>(this: T, value: string): T;
|
|
40
115
|
|
|
116
|
+
export declare function requireEngine(): Engine;
|
|
117
|
+
|
|
41
118
|
export declare type Schema<T extends SchemaFields = SchemaFields> = {
|
|
42
119
|
fields: ZodObject<T>;
|
|
43
120
|
rdfContext: {
|
|
@@ -59,7 +136,13 @@ export declare interface SchemaConfig<T extends SchemaFields> {
|
|
|
59
136
|
|
|
60
137
|
export declare type SchemaFields = Record<string, ZodType>;
|
|
61
138
|
|
|
62
|
-
export declare type SchemaModel<T extends SchemaFields> = typeof Model &
|
|
139
|
+
export declare type SchemaModel<T extends SchemaFields = SchemaFields> = Omit<typeof Model, 'new'> & {
|
|
140
|
+
new (attributes?: z.input<ZodObject<T>> & {
|
|
141
|
+
url?: string;
|
|
142
|
+
}, exists?: boolean): Model & z.infer<ZodObject<T>>;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
export declare function setEngine(engine: Engine): void;
|
|
63
146
|
|
|
64
147
|
export declare type ZodCoreExtensions = typeof coreExtensions;
|
|
65
148
|
|
package/dist/soukai-bis.js
CHANGED
|
@@ -1,103 +1,277 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import {
|
|
5
|
-
import { MagicObject as
|
|
6
|
-
import { expandIRI as
|
|
7
|
-
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
1
|
+
var L = Object.defineProperty;
|
|
2
|
+
var A = (n, e, t) => e in n ? L(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
|
|
3
|
+
var r = (n, e, t) => A(n, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { ZodOptional as N, ZodDefault as O, ZodArray as P, ZodNumber as Z, ZodURL as v, object as I, url as J, z as k } from "zod";
|
|
5
|
+
import { fail as F, MagicObject as U, stringToCamelCase as C, uuid as z, Semaphore as V, requireUrlParentDirectory as g } from "@noeldemartin/utils";
|
|
6
|
+
import { expandIRI as b, RDFNamedNode as d, SolidStore as q, RDFQuad as x, RDFLiteral as H, jsonldToQuads as B, quadsToJsonLD as Q, quadsToTurtle as W } from "@noeldemartin/solid-utils";
|
|
7
|
+
import { openDB as T } from "idb";
|
|
8
|
+
function ot(n, e = !1) {
|
|
9
|
+
for (const [t, s] of Object.entries(n))
|
|
10
|
+
e && s.reset(), s.boot(t);
|
|
11
|
+
}
|
|
12
|
+
let y;
|
|
13
|
+
function it(n) {
|
|
14
|
+
y = n;
|
|
15
|
+
}
|
|
16
|
+
function at() {
|
|
17
|
+
return y;
|
|
18
|
+
}
|
|
19
|
+
function _() {
|
|
20
|
+
return y ?? F("Default engine hasn't been initialized");
|
|
21
|
+
}
|
|
22
|
+
const S = b("rdf:type");
|
|
23
|
+
function h(n) {
|
|
24
|
+
return n instanceof N || n instanceof O ? h(n.def.innerType) : n;
|
|
25
|
+
}
|
|
26
|
+
function j(n, e) {
|
|
27
|
+
return e instanceof Z ? Number(n) : n;
|
|
28
|
+
}
|
|
29
|
+
function Y(n, e, t) {
|
|
30
|
+
const { fields: s, rdfFieldProperties: o } = n.schema, a = new d(e), i = {}, c = new q(t);
|
|
31
|
+
for (const [u, l] of Object.entries(s.shape)) {
|
|
32
|
+
const m = h(l), D = o[u], w = c.statements(a, D);
|
|
33
|
+
if (!(!D || w.length === 0)) {
|
|
34
|
+
if (m instanceof P) {
|
|
35
|
+
const R = h(m.element);
|
|
36
|
+
i[u] = w.map(($) => j($.object.value, R));
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
i[u] = j(w[0].object.value, m);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return n.newInstance({ url: e, ...i }, !0);
|
|
43
|
+
}
|
|
44
|
+
function M(n, e) {
|
|
45
|
+
const t = h(e);
|
|
46
|
+
return t instanceof P ? (Array.isArray(n) ? n : n == null ? [] : [n]).flatMap((o) => M(o, t.def.element)) : t instanceof v ? [new d(String(n))] : [new H(String(n))];
|
|
47
|
+
}
|
|
48
|
+
function E(n) {
|
|
49
|
+
const { fields: e, rdfDefaultResourceHash: t, rdfClasses: s, rdfFieldProperties: o } = n.static().schema, a = new d(n.url ?? `#${t}`), i = [];
|
|
50
|
+
for (const c of s)
|
|
51
|
+
i.push(new x(a, S, c));
|
|
52
|
+
for (const [c, u] of Object.entries(n.getAttributes()))
|
|
53
|
+
for (const l of M(u, e.def.shape[c]))
|
|
54
|
+
i.push(new x(a, o[c], l));
|
|
55
|
+
return i;
|
|
56
|
+
}
|
|
57
|
+
class f extends U {
|
|
58
|
+
constructor(t = {}, s = !1) {
|
|
26
59
|
super();
|
|
27
|
-
|
|
60
|
+
r(this, "__exists", !1);
|
|
61
|
+
r(this, "__attributes");
|
|
28
62
|
if (this.static().isConjuring()) {
|
|
29
63
|
this.__attributes = {};
|
|
30
64
|
return;
|
|
31
65
|
}
|
|
32
|
-
this.__attributes = this.static().schema.fields.parse(
|
|
66
|
+
this.__exists = s, this.__attributes = this.static().schema.fields.parse(t);
|
|
67
|
+
}
|
|
68
|
+
static get collection() {
|
|
69
|
+
return this._collection ?? this.booted()._collection;
|
|
33
70
|
}
|
|
34
|
-
static(
|
|
35
|
-
return
|
|
71
|
+
static get modelName() {
|
|
72
|
+
return this._modelName ?? this.booted()._modelName;
|
|
73
|
+
}
|
|
74
|
+
static boot(t) {
|
|
75
|
+
if (this.__booted)
|
|
76
|
+
throw new Error(`${this.name} model already booted`);
|
|
77
|
+
this._modelName ?? (this._modelName = t ?? this.name), this._collection ?? (this._collection = `solid://${C(this._modelName)}s/`), this.__booted = !0;
|
|
78
|
+
}
|
|
79
|
+
static reset() {
|
|
80
|
+
this.__booted = !1;
|
|
81
|
+
}
|
|
82
|
+
static newInstance(...t) {
|
|
83
|
+
return new this(...t);
|
|
84
|
+
}
|
|
85
|
+
static async all(t) {
|
|
86
|
+
const o = await _().readManyDocuments(t);
|
|
87
|
+
return (await Promise.all(
|
|
88
|
+
Object.entries(o).map(([i, c]) => this.createFromJsonLD(c, { url: i }))
|
|
89
|
+
)).filter((i) => i !== null);
|
|
90
|
+
}
|
|
91
|
+
static async create(...t) {
|
|
92
|
+
return new this(...t).save();
|
|
93
|
+
}
|
|
94
|
+
static async createFromJsonLD(t, s = {}) {
|
|
95
|
+
const o = s.url ?? t["@id"] ?? F("JsonLD is missing @id"), a = await B(t), i = new d(o), c = (u) => a.some(
|
|
96
|
+
(l) => l.subject.value === i.value && l.predicate.value === S && l.object.value === u.value
|
|
97
|
+
);
|
|
98
|
+
return this.schema.rdfClasses.some(c) ? Y(this, o, a) : null;
|
|
99
|
+
}
|
|
100
|
+
static(t) {
|
|
101
|
+
return super.static(t);
|
|
102
|
+
}
|
|
103
|
+
static booted() {
|
|
104
|
+
return this.__booted || (this._modelName ?? (this._modelName = this.name), this._collection ?? (this._collection = `solid://${C(this._modelName)}s/`), this.__booted = !0), this;
|
|
36
105
|
}
|
|
37
106
|
getAttributes() {
|
|
38
107
|
return this.__attributes;
|
|
39
108
|
}
|
|
109
|
+
exists() {
|
|
110
|
+
return this.__exists;
|
|
111
|
+
}
|
|
112
|
+
setExists(t) {
|
|
113
|
+
this.__exists = t;
|
|
114
|
+
}
|
|
115
|
+
async save() {
|
|
116
|
+
this.url ?? (this.url = this.mintUrl());
|
|
117
|
+
const t = await this.toJsonLD();
|
|
118
|
+
return this.__exists ? await _().updateDocument(this.url, t) : await _().createDocument(this.url, t), this.__exists = !0, this;
|
|
119
|
+
}
|
|
40
120
|
async toJsonLD() {
|
|
41
|
-
return
|
|
121
|
+
return Q(E(this));
|
|
42
122
|
}
|
|
43
123
|
async toTurtle() {
|
|
44
|
-
return
|
|
45
|
-
}
|
|
46
|
-
__get(
|
|
47
|
-
return this.__attributes[
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
124
|
+
return W(E(this));
|
|
125
|
+
}
|
|
126
|
+
__get(t) {
|
|
127
|
+
return this.__attributes[t];
|
|
128
|
+
}
|
|
129
|
+
mintUrl() {
|
|
130
|
+
return `${this.static().collection}${z()}`;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
r(f, "schema"), r(f, "_collection"), r(f, "_modelName"), r(f, "__booted", !1);
|
|
134
|
+
function rt(n) {
|
|
135
|
+
var o;
|
|
136
|
+
const e = n.rdfContext ? { default: n.rdfContext } : { default: "solid" }, { default: t, ...s } = e;
|
|
137
|
+
return o = class extends f {
|
|
138
|
+
}, r(o, "schema", {
|
|
139
|
+
fields: I(n.fields).extend({ url: J().optional() }),
|
|
140
|
+
rdfContext: e,
|
|
141
|
+
rdfDefaultResourceHash: n.rdfDefaultResourceHash ?? "it",
|
|
142
|
+
rdfClasses: n.rdfClass ? [
|
|
143
|
+
new d(
|
|
144
|
+
b(n.rdfClass, {
|
|
145
|
+
defaultPrefix: t,
|
|
146
|
+
extraContext: s
|
|
64
147
|
})
|
|
65
148
|
)
|
|
66
149
|
] : [],
|
|
67
150
|
rdfFieldProperties: Object.fromEntries(
|
|
68
|
-
Object.entries(
|
|
69
|
-
|
|
70
|
-
new
|
|
71
|
-
|
|
72
|
-
defaultPrefix:
|
|
73
|
-
extraContext:
|
|
151
|
+
Object.entries(n.fields).map(([a, i]) => [
|
|
152
|
+
a,
|
|
153
|
+
new d(
|
|
154
|
+
b(i.rdfProperty() ?? a, {
|
|
155
|
+
defaultPrefix: t,
|
|
156
|
+
extraContext: s
|
|
74
157
|
})
|
|
75
158
|
)
|
|
76
159
|
])
|
|
77
160
|
)
|
|
78
|
-
}),
|
|
161
|
+
}), o;
|
|
162
|
+
}
|
|
163
|
+
class ct {
|
|
164
|
+
constructor(e = "soukai-bis") {
|
|
165
|
+
r(this, "database");
|
|
166
|
+
r(this, "metadataConnection", null);
|
|
167
|
+
r(this, "documentsConnection", null);
|
|
168
|
+
r(this, "lock");
|
|
169
|
+
this.database = e, this.lock = new V();
|
|
170
|
+
}
|
|
171
|
+
async close() {
|
|
172
|
+
this.metadataConnection && ((await this.metadataConnection).close(), this.metadataConnection = null), this.documentsConnection && ((await this.documentsConnection).close(), this.documentsConnection = null);
|
|
173
|
+
}
|
|
174
|
+
async createDocument(e, t) {
|
|
175
|
+
await this.lock.run(async () => {
|
|
176
|
+
const s = g(e);
|
|
177
|
+
await this.withDocumentsTransaction(s, "readwrite", (o) => o.store.add({ url: e, graph: t }));
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
async updateDocument(e, t) {
|
|
181
|
+
await this.lock.run(async () => {
|
|
182
|
+
const s = g(e);
|
|
183
|
+
await this.collectionExists(s) && await this.withDocumentsTransaction(s, "readwrite", (o) => o.store.put({ url: e, graph: t }));
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
async readManyDocuments(e) {
|
|
187
|
+
return this.lock.run(async () => await this.collectionExists(e) ? (await this.withDocumentsTransaction(e, "readonly", (s) => s.store.getAll())).reduce(
|
|
188
|
+
(s, o) => (s[o.url] = o.graph, s),
|
|
189
|
+
{}
|
|
190
|
+
) : {});
|
|
191
|
+
}
|
|
192
|
+
async createCollection(e) {
|
|
193
|
+
await this.collectionExists(e) || await this.withMetadataTransaction("readwrite", (t) => t.store.add({ name: e }));
|
|
194
|
+
}
|
|
195
|
+
async collectionExists(e) {
|
|
196
|
+
return (await this.getCollections()).includes(e);
|
|
197
|
+
}
|
|
198
|
+
async getCollections() {
|
|
199
|
+
return (await this.withMetadataTransaction("readonly", (t) => t.store.getAll())).map((t) => t.name);
|
|
200
|
+
}
|
|
201
|
+
async withMetadataTransaction(e, t) {
|
|
202
|
+
const o = (await this.getMetadataConnection()).transaction("collections", e);
|
|
203
|
+
return t(o);
|
|
204
|
+
}
|
|
205
|
+
async withDocumentsTransaction(e, t, s) {
|
|
206
|
+
t === "readwrite" && !await this.collectionExists(e) && await this.createCollection(e);
|
|
207
|
+
const a = (await this.getDocumentsConnection()).transaction(e, t);
|
|
208
|
+
return s(a);
|
|
209
|
+
}
|
|
210
|
+
async getMetadataConnection() {
|
|
211
|
+
return this.metadataConnection ? this.metadataConnection : this.metadataConnection = T(`${this.database}-meta`, 1, {
|
|
212
|
+
upgrade(e) {
|
|
213
|
+
e.objectStoreNames.contains("collections") || e.createObjectStore("collections", { keyPath: "name" });
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
async getDocumentsConnection() {
|
|
218
|
+
if (this.documentsConnection)
|
|
219
|
+
return this.documentsConnection;
|
|
220
|
+
const e = await this.getCollections();
|
|
221
|
+
return this.documentsConnection = T(this.database, e.length + 1, {
|
|
222
|
+
upgrade(t) {
|
|
223
|
+
for (const s of e)
|
|
224
|
+
t.objectStoreNames.contains(s) || t.createObjectStore(s, { keyPath: "url" });
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
class ut {
|
|
230
|
+
constructor() {
|
|
231
|
+
r(this, "documents", {});
|
|
232
|
+
}
|
|
233
|
+
async createDocument(e, t) {
|
|
234
|
+
if (e in this.documents)
|
|
235
|
+
throw new Error(`Document already exists: ${e}`);
|
|
236
|
+
this.documents[e] = t;
|
|
237
|
+
}
|
|
238
|
+
async updateDocument(e, t) {
|
|
239
|
+
this.documents[e] = t;
|
|
240
|
+
}
|
|
241
|
+
async readManyDocuments(e) {
|
|
242
|
+
const t = {};
|
|
243
|
+
for (const [s, o] of Object.entries(this.documents))
|
|
244
|
+
s.startsWith(e) && (t[s] = o);
|
|
245
|
+
return t;
|
|
246
|
+
}
|
|
79
247
|
}
|
|
80
|
-
function
|
|
81
|
-
const
|
|
82
|
-
if (
|
|
83
|
-
return e
|
|
84
|
-
if (
|
|
85
|
-
return
|
|
248
|
+
function p(n, e) {
|
|
249
|
+
const t = n.meta();
|
|
250
|
+
if (t && e in t)
|
|
251
|
+
return t[e];
|
|
252
|
+
if (n instanceof O || n instanceof N)
|
|
253
|
+
return p(n.def.innerType, e);
|
|
86
254
|
}
|
|
87
|
-
function
|
|
88
|
-
return typeof
|
|
255
|
+
function G(n) {
|
|
256
|
+
return typeof n != "string" ? p(this, "rdfProperty") : this.meta({ rdfProperty: n });
|
|
89
257
|
}
|
|
90
|
-
const
|
|
258
|
+
const K = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
91
259
|
__proto__: null,
|
|
92
|
-
rdfProperty:
|
|
260
|
+
rdfProperty: G
|
|
93
261
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
94
|
-
function
|
|
95
|
-
for (const [
|
|
96
|
-
|
|
262
|
+
function lt() {
|
|
263
|
+
for (const [n, e] of Object.entries(K))
|
|
264
|
+
k.ZodType.prototype[n] = e;
|
|
97
265
|
}
|
|
98
266
|
export {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
267
|
+
ut as InMemoryEngine,
|
|
268
|
+
ct as IndexedDBEngine,
|
|
269
|
+
f as Model,
|
|
270
|
+
ot as bootModels,
|
|
271
|
+
rt as defineSchema,
|
|
272
|
+
at as getEngine,
|
|
273
|
+
lt as patchZod,
|
|
274
|
+
_ as requireEngine,
|
|
275
|
+
it as setEngine
|
|
102
276
|
};
|
|
103
277
|
//# sourceMappingURL=soukai-bis.js.map
|
package/dist/soukai-bis.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"soukai-bis.js","sources":["../src/models/constants.ts","../src/models/concerns/serializes-to-rdf.ts","../src/models/Model.ts","../src/models/schema.ts","../src/zod/extensions/core.ts","../src/zod/index.ts"],"sourcesContent":["import { expandIRI } from '@noeldemartin/solid-utils';\n\nexport const RDF_TYPE = expandIRI('rdf:type');\n","import { ZodArray, ZodDefault, ZodOptional, ZodURL } from 'zod';\nimport { RDFLiteral, RDFNamedNode, RDFQuad } from '@noeldemartin/solid-utils';\nimport type { Quad, Quad_Object } from '@rdfjs/types';\nimport type { SomeType } from 'zod/v4/core';\n\nimport { RDF_TYPE } from 'soukai-bis/models/constants';\nimport type Model from 'soukai-bis/models/Model';\n\nfunction getFinalType(type: SomeType): SomeType {\n if (type instanceof ZodOptional) {\n return getFinalType(type.def.innerType);\n }\n\n if (type instanceof ZodDefault) {\n return getFinalType(type.def.innerType);\n }\n\n return type;\n}\n\nfunction castValue(value: unknown, type: SomeType): Quad_Object[] {\n const finalType = getFinalType(type);\n\n if (finalType instanceof ZodArray) {\n const arrayValue = Array.isArray(value) ? value : value === null || value === undefined ? [] : [value];\n\n return arrayValue.flatMap((item) => castValue(item, finalType.def.element));\n }\n\n if (finalType instanceof ZodURL) {\n return [new RDFNamedNode(String(value))];\n }\n\n return [new RDFLiteral(String(value))];\n}\n\nexport function serializeToRDF(model: Model): Quad[] {\n const { fields, rdfDefaultResourceHash, rdfClasses, rdfFieldProperties } = model.static().schema;\n const subject = new RDFNamedNode(model.url ?? `#${rdfDefaultResourceHash}`);\n const statements: Quad[] = [];\n\n for (const rdfClass of rdfClasses) {\n statements.push(new RDFQuad(subject, RDF_TYPE, rdfClass));\n }\n\n for (const [field, value] of Object.entries(model.getAttributes())) {\n for (const object of castValue(value, fields.def.shape[field])) {\n statements.push(new RDFQuad(subject, rdfFieldProperties[field], object));\n }\n }\n\n return statements;\n}\n","import { MagicObject } from '@noeldemartin/utils';\nimport { quadsToJsonLD, quadsToTurtle } from '@noeldemartin/solid-utils';\nimport type { JsonLD } from '@noeldemartin/solid-utils';\n\nimport { serializeToRDF } from './concerns/serializes-to-rdf';\nimport type { Schema } from './schema';\n\nexport default class Model extends MagicObject {\n\n public static schema: Schema;\n\n public static<T extends typeof Model>(): T;\n public static<T extends typeof Model, K extends keyof T>(property: K): T[K];\n public static<T extends typeof Model, K extends keyof T>(property?: K): T | T[K] {\n return super.static<T, K>(property as K);\n }\n\n declare public url?: string;\n private __attributes: Record<string, unknown>;\n\n public constructor(attributes: Record<string, unknown> = {}) {\n super();\n\n if (this.static().isConjuring()) {\n this.__attributes = {};\n\n return;\n }\n\n this.__attributes = this.static().schema.fields.parse(attributes);\n }\n\n public getAttributes(): Record<string, unknown> {\n return this.__attributes;\n }\n\n public async toJsonLD(): Promise<JsonLD> {\n return quadsToJsonLD(serializeToRDF(this));\n }\n\n public async toTurtle(): Promise<string> {\n return quadsToTurtle(serializeToRDF(this));\n }\n\n protected __get(property: string): unknown {\n return this.__attributes[property];\n }\n\n}\n","import { object } from 'zod';\nimport { RDFNamedNode, expandIRI } from '@noeldemartin/solid-utils';\nimport type { Constructor } from '@noeldemartin/utils';\nimport type { ZodObject, ZodType, z } from 'zod';\nimport type { NamedNode } from '@rdfjs/types';\n\nimport Model from './Model';\n\nexport type Schema<T extends SchemaFields = SchemaFields> = {\n fields: ZodObject<T>;\n rdfContext: { default: string } & Record<string, string>;\n rdfClasses: NamedNode[];\n rdfDefaultResourceHash: string;\n rdfFieldProperties: Record<string, NamedNode>;\n};\nexport type SchemaModel<T extends SchemaFields> = typeof Model & Constructor<z.infer<ZodObject<T>>>;\nexport type SchemaFields = Record<string, ZodType>;\n\nexport interface SchemaConfig<T extends SchemaFields> {\n crdts?: boolean;\n rdfContext?: string;\n rdfClass?: string;\n rdfDefaultResourceHash?: string;\n fields: T;\n relations?: Record<string, unknown>;\n}\n\nexport function defineSchema<T extends SchemaFields>(config: SchemaConfig<T>): SchemaModel<T> {\n const rdfContext = config.rdfContext ? { default: config.rdfContext } : { default: 'solid' };\n const { default: defaultPrefix, ...extraContext } = rdfContext;\n\n return class extends Model {\n\n public static schema = {\n fields: object(config.fields) as unknown as ZodObject,\n rdfContext,\n rdfDefaultResourceHash: config.rdfDefaultResourceHash ?? 'it',\n rdfClasses: config.rdfClass\n ? [\n new RDFNamedNode(\n expandIRI(config.rdfClass, {\n defaultPrefix,\n extraContext,\n }),\n ),\n ]\n : [],\n rdfFieldProperties: Object.fromEntries(\n Object.entries(config.fields).map(([field, definition]) => [\n field,\n new RDFNamedNode(\n expandIRI(definition.rdfProperty() ?? field, {\n defaultPrefix,\n extraContext,\n }),\n ),\n ]),\n ),\n };\n \n } as SchemaModel<T>;\n}\n","import { ZodDefault, ZodOptional } from 'zod';\nimport type { ZodType } from 'zod';\n\nfunction getDeepMeta<T extends keyof CustomMeta>(type: ZodType, key: T): CustomMeta[T] | undefined {\n const meta = type.meta();\n\n if (meta && key in meta) {\n return meta[key];\n }\n\n if (type instanceof ZodDefault) {\n return getDeepMeta(type.def.innerType as ZodType, key);\n }\n\n if (type instanceof ZodOptional) {\n return getDeepMeta(type.def.innerType as ZodType, key);\n }\n\n return undefined;\n}\n\nexport interface CustomMeta {\n rdfProperty?: string;\n}\n\nexport function rdfProperty<T extends ZodType>(this: T): string | undefined;\nexport function rdfProperty<T extends ZodType>(this: T, value: string): T;\nexport function rdfProperty<T extends ZodType>(this: T, value?: string): T | string | undefined {\n if (typeof value !== 'string') {\n return getDeepMeta(this, 'rdfProperty');\n }\n\n return this.meta({ rdfProperty: value });\n}\n\ndeclare module 'zod' {\n interface GlobalMeta extends CustomMeta {}\n}\n","// This folder is used to extend Zod's native functionality with Soukai features by patching the prototypes\n// of core classes. This may seem like an anti-pattern, but it's actually been recommended by the author of Zod.\n//\n// See https://github.com/colinhacks/zod/pull/3445#issuecomment-2091463120\n\nimport { z } from 'zod';\nimport * as coreExtensions from './extensions/core';\n\nexport type ZodCoreExtensions = typeof coreExtensions;\n\nexport function patchZod(): void {\n for (const [method, implementation] of Object.entries(coreExtensions)) {\n z.ZodType.prototype[method] = implementation;\n }\n}\n\ndeclare module 'zod' {\n interface ZodType extends ZodCoreExtensions {}\n}\n"],"names":["RDF_TYPE","expandIRI","getFinalType","type","ZodOptional","ZodDefault","castValue","value","finalType","ZodArray","item","ZodURL","RDFNamedNode","RDFLiteral","serializeToRDF","model","fields","rdfDefaultResourceHash","rdfClasses","rdfFieldProperties","subject","statements","rdfClass","RDFQuad","field","object","Model","MagicObject","attributes","__publicField","property","quadsToJsonLD","quadsToTurtle","defineSchema","config","rdfContext","defaultPrefix","extraContext","_a","definition","getDeepMeta","key","meta","rdfProperty","patchZod","method","implementation","coreExtensions","z"],"mappings":";;;;;;AAEO,MAAMA,IAAWC,EAAU,UAAU;ACM5C,SAASC,EAAaC,GAA0B;AAK5C,SAJIA,aAAgBC,KAIhBD,aAAgBE,IACTH,EAAaC,EAAK,IAAI,SAAS,IAGnCA;AACX;AAEA,SAASG,EAAUC,GAAgBJ,GAA+B;AAC9D,QAAMK,IAAYN,EAAaC,CAAI;AAEnC,SAAIK,aAAqBC,KACF,MAAM,QAAQF,CAAK,IAAIA,IAAQA,KAAU,OAA8B,CAAA,IAAK,CAACA,CAAK,GAEnF,QAAQ,CAACG,MAASJ,EAAUI,GAAMF,EAAU,IAAI,OAAO,CAAC,IAG1EA,aAAqBG,IACd,CAAC,IAAIC,EAAa,OAAOL,CAAK,CAAC,CAAC,IAGpC,CAAC,IAAIM,EAAW,OAAON,CAAK,CAAC,CAAC;AACzC;AAEO,SAASO,EAAeC,GAAsB;AACjD,QAAM,EAAE,QAAAC,GAAQ,wBAAAC,GAAwB,YAAAC,GAAY,oBAAAC,MAAuBJ,EAAM,SAAS,QACpFK,IAAU,IAAIR,EAAaG,EAAM,OAAO,IAAIE,CAAsB,EAAE,GACpEI,IAAqB,CAAA;AAE3B,aAAWC,KAAYJ;AACnB,IAAAG,EAAW,KAAK,IAAIE,EAAQH,GAASpB,GAAU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AAAA,MACE,IAAItB;AAAA,QACAX,EAAUiC,EAAO,UAAU;AAAA,UACvB,eAAAE;AAAA,UACA,cAAAC;AAAA,QAAA,CACH;AAAA,MAAA;AAAA,IACL,IAEF,CAAA;AAAA,IACN,oBAAoB,OAAO;AAAA,MACvB,OAAO,QAAQH,EAAO,MAAM,EAAE,IAAI,CAAC,CAACV,GAAOe,CAAU,MAAM;AAAA,QACvDf;AAAA,QACA,IAAIZ;AAAA,UACAX,EAAUsC,EAAW,YAAA,KAAiBf,GAAO;AAAA,YACzC,eAAAY;AAAA,YACA,cAAAC;AAAA,UAAA,CACH;AAAA,QAAA;AAAA,MACL,CACH;AAAA,IAAA;AAAA,EACL,IA1BDC;AA8BX;AC1DA,SAASE,EAAwCrC,GAAesC,GAAmC;AAC/F,QAAMC,IAAOvC,EAAK,KAAA;AAElB,MAAIuC,KAAQD,KAAOC;AACf,WAAOA,EAAKD,CAAG;AAOnB,MAJItC,aAAgBE,KAIhBF,aAAgBC;AAChB,WAAOoC,EAAYrC,EAAK,IAAI,WAAsBsC,CAAG;AAI7D;AAQO,SAASE,EAAwCpC,GAAwC;AAC5F,SAAI,OAAOA,KAAU,WACViC,EAAY,MAAM,aAAa,IAGnC,KAAK,KAAK,EAAE,aAAajC,GAAO;AAC3C;;;;;ACvBO,SAASqC,IAAiB;AAC7B,aAAW,CAACC,GAAQC,CAAc,KAAK,OAAO,QAAQC,CAAc;AAChE,IAAAC,EAAE,QAAQ,UAAUH,CAAM,IAAIC;AAEtC;"}
|
|
1
|
+
{"version":3,"file":"soukai-bis.js","sources":["../src/models/helpers.ts","../src/engines/state.ts","../src/models/constants.ts","../src/zod/utils.ts","../src/models/concerns/creates-from-rdf.ts","../src/models/concerns/serializes-to-rdf.ts","../src/models/Model.ts","../src/models/schema.ts","../src/engines/IndexedDBEngine.ts","../src/engines/InMemoryEngine.ts","../src/zod/extensions/core.ts","../src/zod/index.ts"],"sourcesContent":["export function bootModels(\n models: Record<string, { boot(name: string): unknown; reset(): void }>,\n reset: boolean = false,\n): void {\n for (const [modelName, modelClass] of Object.entries(models)) {\n reset && modelClass.reset();\n\n modelClass.boot(modelName);\n }\n}\n","import { fail } from '@noeldemartin/utils';\nimport type { Engine } from './Engine';\n\nlet _engine: Engine | undefined;\n\nexport function setEngine(engine: Engine): void {\n _engine = engine;\n}\n\nexport function getEngine(): Engine | undefined {\n return _engine;\n}\n\nexport function requireEngine(): Engine {\n return _engine ?? fail('Default engine hasn\\'t been initialized');\n}\n","import { expandIRI } from '@noeldemartin/solid-utils';\n\nexport const RDF_TYPE = expandIRI('rdf:type');\n","import { ZodDefault, ZodOptional } from 'zod';\nimport type { SomeType } from 'zod/v4/core';\n\nexport function getFinalType(type: SomeType): SomeType {\n if (type instanceof ZodOptional) {\n return getFinalType(type.def.innerType);\n }\n\n if (type instanceof ZodDefault) {\n return getFinalType(type.def.innerType);\n }\n\n return type;\n}\n","import { RDFNamedNode, SolidStore } from '@noeldemartin/solid-utils';\nimport { ZodArray, ZodNumber } from 'zod';\nimport type { Quad } from '@rdfjs/types';\nimport type { SomeType } from 'zod/v4/core';\n\nimport { getFinalType } from 'soukai-bis/zod/utils';\nimport type Model from 'soukai-bis/models/Model';\nimport type { MintedModel, ModelConstructor } from 'soukai-bis/models/types';\n\nfunction castValue(value: string, type: SomeType): unknown {\n if (type instanceof ZodNumber) {\n return Number(value);\n }\n\n return value;\n}\n\nexport function createFromRDF<T extends Model>(\n modelClass: ModelConstructor<T>,\n url: string,\n quads: Quad[],\n): MintedModel<T> {\n const { fields, rdfFieldProperties } = modelClass.schema;\n const subject = new RDFNamedNode(url);\n const attributes: Record<string, unknown> = {};\n const store = new SolidStore(quads);\n\n for (const [field, type] of Object.entries(fields.shape)) {\n const fieldType = getFinalType(type);\n const property = rdfFieldProperties[field];\n const values = store.statements(subject, property);\n\n if (!property || values.length === 0) {\n continue;\n }\n\n if (fieldType instanceof ZodArray) {\n const itemType = getFinalType(fieldType.element);\n\n attributes[field] = values.map((item) => castValue(item.object.value, itemType));\n\n continue;\n }\n\n attributes[field] = castValue(values[0].object.value, fieldType);\n }\n\n return modelClass.newInstance({ url, ...attributes }, true) as MintedModel<T>;\n}\n","import { ZodArray, ZodURL } from 'zod';\nimport { RDFLiteral, RDFNamedNode, RDFQuad } from '@noeldemartin/solid-utils';\nimport type { Quad, Quad_Object } from '@rdfjs/types';\nimport type { SomeType } from 'zod/v4/core';\n\nimport { RDF_TYPE } from 'soukai-bis/models/constants';\nimport { getFinalType } from 'soukai-bis/zod/utils';\nimport type Model from 'soukai-bis/models/Model';\n\nfunction castValue(value: unknown, type: SomeType): Quad_Object[] {\n const finalType = getFinalType(type);\n\n if (finalType instanceof ZodArray) {\n const arrayValue = Array.isArray(value) ? value : value === null || value === undefined ? [] : [value];\n\n return arrayValue.flatMap((item) => castValue(item, finalType.def.element));\n }\n\n if (finalType instanceof ZodURL) {\n return [new RDFNamedNode(String(value))];\n }\n\n return [new RDFLiteral(String(value))];\n}\n\nexport function serializeToRDF(model: Model): Quad[] {\n const { fields, rdfDefaultResourceHash, rdfClasses, rdfFieldProperties } = model.static().schema;\n const subject = new RDFNamedNode(model.url ?? `#${rdfDefaultResourceHash}`);\n const statements: Quad[] = [];\n\n for (const rdfClass of rdfClasses) {\n statements.push(new RDFQuad(subject, RDF_TYPE, rdfClass));\n }\n\n for (const [field, value] of Object.entries(model.getAttributes())) {\n for (const object of castValue(value, fields.def.shape[field])) {\n statements.push(new RDFQuad(subject, rdfFieldProperties[field], object));\n }\n }\n\n return statements;\n}\n","import { MagicObject, fail, stringToCamelCase, uuid } from '@noeldemartin/utils';\nimport { RDFNamedNode, jsonldToQuads, quadsToJsonLD, quadsToTurtle } from '@noeldemartin/solid-utils';\nimport type { JsonLD } from '@noeldemartin/solid-utils';\nimport type { NamedNode } from '@rdfjs/types';\n\nimport { requireEngine } from 'soukai-bis/engines/state';\nimport { RDF_TYPE } from './constants';\nimport { createFromRDF } from './concerns/creates-from-rdf';\nimport { serializeToRDF } from './concerns/serializes-to-rdf';\nimport type { Schema } from './schema';\nimport type { BootedModelClass, MintedModel, ModelConstructor } from './types';\n\nexport default class Model extends MagicObject {\n\n public static schema: Schema;\n protected static _collection?: string;\n protected static _modelName?: string;\n private static __booted: boolean = false;\n\n public static get collection(): string {\n return this._collection ?? this.booted()._collection;\n }\n\n public static get modelName(): string {\n return this._modelName ?? this.booted()._modelName;\n }\n\n public static boot<T extends typeof Model>(this: T, name?: string): void {\n if (this.__booted) {\n throw new Error(`${this.name} model already booted`);\n }\n\n this._modelName ??= name ?? this.name;\n this._collection ??= `solid://${stringToCamelCase(this._modelName)}s/`;\n this.__booted = true;\n }\n\n public static reset(): void {\n this.__booted = false;\n }\n\n public static newInstance<T extends Model>(\n this: ModelConstructor<T>,\n ...params: ConstructorParameters<ModelConstructor<T>>\n ): T {\n return new this(...params);\n }\n\n public static async all<T extends Model>(\n this: ModelConstructor<T>,\n containerUrl: string,\n ): Promise<MintedModel<T>[]> {\n const engine = requireEngine();\n const documents = await engine.readManyDocuments(containerUrl);\n const models = await Promise.all(\n Object.entries(documents).map(([url, document]) => this.createFromJsonLD(document, { url })),\n );\n\n return models.filter((model) => model !== null) as MintedModel<T>[];\n }\n\n public static async create<T extends Model>(\n this: ModelConstructor<T>,\n ...args: ConstructorParameters<ModelConstructor<T>>\n ): Promise<MintedModel<T>> {\n const model = new this(...args);\n\n return model.save();\n }\n\n public static async createFromJsonLD<T extends Model>(\n this: ModelConstructor<T>,\n json: JsonLD,\n options: { url?: string } = {},\n ): Promise<MintedModel<T> | null> {\n const url = options.url ?? json['@id'] ?? fail<string>('JsonLD is missing @id');\n const quads = await jsonldToQuads(json);\n const subject = new RDFNamedNode(url);\n const isType = (rdfClass: NamedNode) =>\n quads.some(\n (q) =>\n q.subject.value === subject.value &&\n q.predicate.value === RDF_TYPE &&\n q.object.value === rdfClass.value,\n );\n\n if (!this.schema.rdfClasses.some(isType)) {\n return null;\n }\n\n return createFromRDF<T>(this, url, quads);\n }\n\n public static<T extends typeof Model>(): T;\n public static<T extends typeof Model, K extends keyof T>(property: K): T[K];\n public static<T extends typeof Model, K extends keyof T>(property?: K): T | T[K] {\n return super.static<T, K>(property as K);\n }\n\n private static booted<T extends typeof Model>(this: T): BootedModelClass<T> {\n if (!this.__booted) {\n this._modelName ??= this.name;\n this._collection ??= `solid://${stringToCamelCase(this._modelName)}s/`;\n this.__booted = true;\n }\n\n return this as BootedModelClass<T>;\n }\n\n declare public url?: string;\n private __exists: boolean = false;\n private __attributes: Record<string, unknown>;\n\n public constructor(attributes: Record<string, unknown> = {}, exists: boolean = false) {\n super();\n\n if (this.static().isConjuring()) {\n this.__attributes = {};\n\n return;\n }\n this.__exists = exists;\n this.__attributes = this.static().schema.fields.parse(attributes);\n }\n\n public getAttributes(): Record<string, unknown> {\n return this.__attributes;\n }\n\n public exists(): boolean {\n return this.__exists;\n }\n\n public setExists(exists: boolean): void {\n this.__exists = exists;\n }\n\n public async save(): Promise<MintedModel<this>> {\n this.url ??= this.mintUrl();\n\n const graph = await this.toJsonLD();\n\n this.__exists\n ? await requireEngine().updateDocument(this.url, graph)\n : await requireEngine().createDocument(this.url, graph);\n\n this.__exists = true;\n\n return this as MintedModel<this>;\n }\n\n public async toJsonLD(): Promise<JsonLD> {\n return quadsToJsonLD(serializeToRDF(this));\n }\n\n public async toTurtle(): Promise<string> {\n return quadsToTurtle(serializeToRDF(this));\n }\n\n protected __get(property: string): unknown {\n return this.__attributes[property];\n }\n\n protected mintUrl(): string {\n return `${this.static().collection}${uuid()}`;\n }\n\n}\n","import { object, url } from 'zod';\nimport { RDFNamedNode, expandIRI } from '@noeldemartin/solid-utils';\nimport type { ZodObject, ZodType, z } from 'zod';\nimport type { NamedNode } from '@rdfjs/types';\n\nimport Model from './Model';\n\nexport type Schema<T extends SchemaFields = SchemaFields> = {\n fields: ZodObject<T>;\n rdfContext: { default: string } & Record<string, string>;\n rdfClasses: NamedNode[];\n rdfDefaultResourceHash: string;\n rdfFieldProperties: Record<string, NamedNode>;\n};\n\nexport type SchemaModel<T extends SchemaFields = SchemaFields> = Omit<typeof Model, 'new'> & {\n new (attributes?: z.input<ZodObject<T>> & { url?: string }, exists?: boolean): Model & z.infer<ZodObject<T>>;\n};\n\nexport type SchemaFields = Record<string, ZodType>;\n\nexport interface SchemaConfig<T extends SchemaFields> {\n crdts?: boolean;\n rdfContext?: string;\n rdfClass?: string;\n rdfDefaultResourceHash?: string;\n fields: T;\n relations?: Record<string, unknown>;\n}\n\nexport function defineSchema<T extends SchemaFields>(config: SchemaConfig<T>): SchemaModel<T> {\n const rdfContext = config.rdfContext ? { default: config.rdfContext } : { default: 'solid' };\n const { default: defaultPrefix, ...extraContext } = rdfContext;\n\n return class extends Model {\n\n public static schema = {\n fields: object(config.fields).extend({ url: url().optional() }) as unknown as ZodObject,\n rdfContext,\n rdfDefaultResourceHash: config.rdfDefaultResourceHash ?? 'it',\n rdfClasses: config.rdfClass\n ? [\n new RDFNamedNode(\n expandIRI(config.rdfClass, {\n defaultPrefix,\n extraContext,\n }),\n ),\n ]\n : [],\n rdfFieldProperties: Object.fromEntries(\n Object.entries(config.fields).map(([field, definition]) => [\n field,\n new RDFNamedNode(\n expandIRI(definition.rdfProperty() ?? field, {\n defaultPrefix,\n extraContext,\n }),\n ),\n ]),\n ),\n };\n \n } as unknown as SchemaModel<T>;\n}\n","import { openDB } from 'idb';\nimport { Semaphore, requireUrlParentDirectory } from '@noeldemartin/utils';\nimport type { DBSchema, IDBPDatabase, IDBPTransaction } from 'idb';\nimport type { JsonLD } from '@noeldemartin/solid-utils';\n\nimport type { Engine } from './Engine';\n\nexport interface LocalDocument {\n url: string;\n graph: JsonLD;\n}\n\ninterface DocumentsSchema extends DBSchema {\n '[containerUrl]': {\n key: string;\n value: LocalDocument;\n };\n}\n\ninterface MetadataSchema extends DBSchema {\n collections: {\n key: string;\n value: {\n name: string;\n };\n };\n}\n\nexport class IndexedDBEngine implements Engine {\n\n private database: string;\n private metadataConnection: Promise<IDBPDatabase<MetadataSchema>> | null = null;\n private documentsConnection: Promise<IDBPDatabase<DocumentsSchema>> | null = null;\n private lock: Semaphore;\n\n public constructor(database: string = 'soukai-bis') {\n this.database = database;\n this.lock = new Semaphore();\n }\n\n public async close(): Promise<void> {\n if (this.metadataConnection) {\n (await this.metadataConnection).close();\n this.metadataConnection = null;\n }\n\n if (this.documentsConnection) {\n (await this.documentsConnection).close();\n this.documentsConnection = null;\n }\n }\n\n public async createDocument(url: string, graph: JsonLD): Promise<void> {\n await this.lock.run(async () => {\n const containerUrl = requireUrlParentDirectory(url);\n\n await this.withDocumentsTransaction(containerUrl, 'readwrite', (transaction) => {\n return transaction.store.add({ url, graph });\n });\n });\n }\n\n public async updateDocument(url: string, graph: JsonLD): Promise<void> {\n await this.lock.run(async () => {\n const containerUrl = requireUrlParentDirectory(url);\n\n if (!(await this.collectionExists(containerUrl))) {\n return;\n }\n\n await this.withDocumentsTransaction(containerUrl, 'readwrite', (transaction) => {\n return transaction.store.put({ url, graph });\n });\n });\n }\n\n public async readManyDocuments(containerUrl: string): Promise<Record<string, JsonLD>> {\n return this.lock.run(async () => {\n if (!(await this.collectionExists(containerUrl))) {\n return {};\n }\n\n const documents = await this.withDocumentsTransaction(containerUrl, 'readonly', (transaction) => {\n return transaction.store.getAll();\n });\n\n return documents.reduce(\n (graph, document) => {\n graph[document.url] = document.graph;\n\n return graph;\n },\n {} as Record<string, JsonLD>,\n );\n });\n }\n\n private async createCollection(collection: string): Promise<void> {\n if (await this.collectionExists(collection)) {\n return;\n }\n\n await this.withMetadataTransaction('readwrite', (transaction) => {\n return transaction.store.add({ name: collection });\n });\n }\n\n private async collectionExists(collection: string): Promise<boolean> {\n const collections = await this.getCollections();\n\n return collections.includes(collection);\n }\n\n private async getCollections(): Promise<string[]> {\n const documents = await this.withMetadataTransaction('readonly', (transaction) => {\n return transaction.store.getAll();\n });\n\n return documents.map((document) => document.name);\n }\n\n private async withMetadataTransaction<TResult, TMode extends IDBTransactionMode>(\n mode: TMode,\n operation: (transaction: IDBPTransaction<MetadataSchema, ['collections'], TMode>) => Promise<TResult>,\n ): Promise<TResult> {\n const connection = await this.getMetadataConnection();\n const transaction = connection.transaction('collections', mode);\n\n return operation(transaction);\n }\n\n private async withDocumentsTransaction<TResult, TMode extends IDBTransactionMode>(\n collection: string,\n mode: TMode,\n operation: (transaction: IDBPTransaction<DocumentsSchema, ['[containerUrl]'], TMode>) => Promise<TResult>,\n ): Promise<TResult> {\n if (mode === 'readwrite' && !(await this.collectionExists(collection))) {\n await this.createCollection(collection);\n }\n\n const connection = await this.getDocumentsConnection();\n const transaction = connection.transaction(collection as '[containerUrl]', mode);\n\n return operation(transaction);\n }\n\n private async getMetadataConnection(): Promise<IDBPDatabase<MetadataSchema>> {\n if (this.metadataConnection) {\n return this.metadataConnection;\n }\n\n return (this.metadataConnection = openDB<MetadataSchema>(`${this.database}-meta`, 1, {\n upgrade(db) {\n if (db.objectStoreNames.contains('collections')) {\n return;\n }\n\n db.createObjectStore('collections', { keyPath: 'name' });\n },\n }));\n }\n\n private async getDocumentsConnection(): Promise<IDBPDatabase<DocumentsSchema>> {\n if (this.documentsConnection) {\n return this.documentsConnection;\n }\n\n const collections = await this.getCollections();\n\n return (this.documentsConnection = openDB<DocumentsSchema>(this.database, collections.length + 1, {\n upgrade(database) {\n for (const collection of collections) {\n if (database.objectStoreNames.contains(collection as '[containerUrl]')) {\n continue;\n }\n\n database.createObjectStore(collection as '[containerUrl]', { keyPath: 'url' });\n }\n },\n }));\n }\n\n}\n","import type { JsonLD } from '@noeldemartin/solid-utils';\n\nimport type { Engine } from './Engine';\n\nexport class InMemoryEngine implements Engine {\n\n public documents: Record<string, JsonLD> = {};\n\n public async createDocument(url: string, graph: JsonLD): Promise<void> {\n if (url in this.documents) {\n throw new Error(`Document already exists: ${url}`);\n }\n\n this.documents[url] = graph;\n }\n\n public async updateDocument(url: string, graph: JsonLD): Promise<void> {\n this.documents[url] = graph;\n }\n\n public async readManyDocuments(containerUrl: string): Promise<Record<string, JsonLD>> {\n const documents: Record<string, JsonLD> = {};\n\n for (const [url, graph] of Object.entries(this.documents)) {\n if (!url.startsWith(containerUrl)) {\n continue;\n }\n\n documents[url] = graph;\n }\n\n return documents;\n }\n\n}\n","import { ZodDefault, ZodOptional } from 'zod';\nimport type { ZodType } from 'zod';\n\nfunction getDeepMeta<T extends keyof CustomMeta>(type: ZodType, key: T): CustomMeta[T] | undefined {\n const meta = type.meta();\n\n if (meta && key in meta) {\n return meta[key];\n }\n\n if (type instanceof ZodDefault) {\n return getDeepMeta(type.def.innerType as ZodType, key);\n }\n\n if (type instanceof ZodOptional) {\n return getDeepMeta(type.def.innerType as ZodType, key);\n }\n\n return undefined;\n}\n\nexport interface CustomMeta {\n rdfProperty?: string;\n}\n\nexport function rdfProperty<T extends ZodType>(this: T): string | undefined;\nexport function rdfProperty<T extends ZodType>(this: T, value: string): T;\nexport function rdfProperty<T extends ZodType>(this: T, value?: string): T | string | undefined {\n if (typeof value !== 'string') {\n return getDeepMeta(this, 'rdfProperty');\n }\n\n return this.meta({ rdfProperty: value });\n}\n\ndeclare module 'zod' {\n interface GlobalMeta extends CustomMeta {}\n}\n","// This folder is used to extend Zod's native functionality with Soukai features by patching the prototypes\n// of core classes. This may seem like an anti-pattern, but it's actually been recommended by the author of Zod.\n//\n// See https://github.com/colinhacks/zod/pull/3445#issuecomment-2091463120\n\nimport { z } from 'zod';\nimport * as coreExtensions from './extensions/core';\n\nexport type ZodCoreExtensions = typeof coreExtensions;\n\nexport function patchZod(): void {\n for (const [method, implementation] of Object.entries(coreExtensions)) {\n z.ZodType.prototype[method] = implementation;\n }\n}\n\ndeclare module 'zod' {\n interface ZodType extends ZodCoreExtensions {}\n}\n"],"names":["bootModels","models","reset","modelName","modelClass","_engine","setEngine","engine","getEngine","requireEngine","fail","RDF_TYPE","expandIRI","getFinalType","type","ZodOptional","ZodDefault","castValue","value","ZodNumber","createFromRDF","url","quads","fields","rdfFieldProperties","subject","RDFNamedNode","attributes","store","SolidStore","field","fieldType","property","values","ZodArray","itemType","item","finalType","ZodURL","RDFLiteral","serializeToRDF","model","rdfDefaultResourceHash","rdfClasses","statements","rdfClass","RDFQuad","object","Model","MagicObject","exists","__publicField","name","stringToCamelCase","params","containerUrl","documents","document","args","json","options","jsonldToQuads","isType","q","graph","quadsToJsonLD","quadsToTurtle","uuid","defineSchema","config","rdfContext","defaultPrefix","extraContext","_a","definition","IndexedDBEngine","database","Semaphore","requireUrlParentDirectory","transaction","collection","mode","operation","openDB","db","collections","InMemoryEngine","getDeepMeta","key","meta","rdfProperty","patchZod","method","implementation","coreExtensions","z"],"mappings":";;;;;;;AAAO,SAASA,GACZC,GACAC,IAAiB,IACb;AACJ,aAAW,CAACC,GAAWC,CAAU,KAAK,OAAO,QAAQH,CAAM;AACvD,IAAAC,KAASE,EAAW,MAAA,GAEpBA,EAAW,KAAKD,CAAS;AAEjC;ACNA,IAAIE;AAEG,SAASC,GAAUC,GAAsB;AAC5C,EAAAF,IAAUE;AACd;AAEO,SAASC,KAAgC;AAC5C,SAAOH;AACX;AAEO,SAASI,IAAwB;AACpC,SAAOJ,KAAWK,EAAK,wCAAyC;AACpE;ACbO,MAAMC,IAAWC,EAAU,UAAU;ACCrC,SAASC,EAAaC,GAA0B;AAKnD,SAJIA,aAAgBC,KAIhBD,aAAgBE,IACTH,EAAaC,EAAK,IAAI,SAAS,IAGnCA;AACX;ACJA,SAASG,EAAUC,GAAeJ,GAAyB;AACvD,SAAIA,aAAgBK,IACT,OAAOD,CAAK,IAGhBA;AACX;AAEO,SAASE,EACZhB,GACAiB,GACAC,GACc;AACd,QAAM,EAAE,QAAAC,GAAQ,oBAAAC,EAAA,IAAuBpB,EAAW,QAC5CqB,IAAU,IAAIC,EAAaL,CAAG,GAC9BM,IAAsC,CAAA,GACtCC,IAAQ,IAAIC,EAAWP,CAAK;AAElC,aAAW,CAACQ,GAAOhB,CAAI,KAAK,OAAO,QAAQS,EAAO,KAAK,GAAG;AACtD,UAAMQ,IAAYlB,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AAY,MAAM,aAAa,IAGnC,KAAK,KAAK,EAAE,aAAarE,GAAO;AAC3C;;;;;ACvBO,SAASyE,KAAiB;AAC7B,aAAW,CAACC,GAAQC,CAAc,KAAK,OAAO,QAAQC,CAAc;AAChE,IAAAC,EAAE,QAAQ,UAAUH,CAAM,IAAIC;AAEtC;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "soukai-bis",
|
|
3
|
-
"version": "0.0.0-next.
|
|
3
|
+
"version": "0.0.0-next.f91035aead5d66e83db383d8022a10f851222e7d",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"exports": {
|
|
@@ -14,25 +14,32 @@
|
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"author": "Noel De Martin",
|
|
16
16
|
"repository": "github:NoelDeMartin/soukai",
|
|
17
|
+
"peerDependencies": {
|
|
18
|
+
"zod": "^4.3.4"
|
|
19
|
+
},
|
|
17
20
|
"dependencies": {
|
|
18
21
|
"@noeldemartin/solid-utils": "next",
|
|
19
22
|
"@noeldemartin/utils": "next",
|
|
20
|
-
"
|
|
23
|
+
"idb": "^8.0.3"
|
|
21
24
|
},
|
|
22
25
|
"devDependencies": {
|
|
23
26
|
"@arethetypeswrong/cli": "^0.17.4",
|
|
24
27
|
"@braintree/sanitize-url": "^7.1.1",
|
|
28
|
+
"@noeldemartin/faker": "7.6.0",
|
|
25
29
|
"@noeldemartin/scripts": "next",
|
|
30
|
+
"@noeldemartin/testing": "next",
|
|
26
31
|
"@rdfjs/types": "^2.0.1",
|
|
27
32
|
"cytoscape": "^3.33.1",
|
|
28
33
|
"cytoscape-cose-bilkent": "^4.1.0",
|
|
29
34
|
"dayjs": "^1.11.19",
|
|
30
35
|
"debug": "^4.4.3",
|
|
31
36
|
"eslint": "^8.57.1",
|
|
37
|
+
"fake-indexeddb": "^6.0.1",
|
|
32
38
|
"mermaid": "^11.12.2",
|
|
33
39
|
"publint": "^0.3.12",
|
|
34
40
|
"vitepress": "2.0.0-alpha.15",
|
|
35
|
-
"vitepress-plugin-mermaid": "^2.0.17"
|
|
41
|
+
"vitepress-plugin-mermaid": "^2.0.17",
|
|
42
|
+
"zod": "^4.3.4"
|
|
36
43
|
},
|
|
37
44
|
"eslintConfig": {
|
|
38
45
|
"extends": [
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { JsonLD } from '@noeldemartin/solid-utils';
|
|
2
|
+
|
|
3
|
+
export interface Engine {
|
|
4
|
+
createDocument(url: string, graph: JsonLD): Promise<void>;
|
|
5
|
+
updateDocument(url: string, graph: JsonLD): Promise<void>;
|
|
6
|
+
readManyDocuments(containerUrl: string): Promise<Record<string, JsonLD>>;
|
|
7
|
+
}
|