@utilarium/overcontext 0.0.7 → 0.0.8-dev.20260226040805.d18adcf

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -7,6 +7,12 @@ export { EntityNotFoundError, NamespaceNotFoundError, ReadonlyStorageError, Sche
7
7
  export { createObservableProvider } from './storage/observable.js';
8
8
  export { createFileSystemProvider } from './storage/filesystem.js';
9
9
  export { createMemoryProvider } from './storage/memory.js';
10
+ export { FjellStorageProvider } from './storage/fjell/provider.js';
11
+ export { MemoryFjellAdapter } from './storage/fjell/memory-adapter.js';
12
+ export { FjellFsAdapter } from './storage/fjell/fs-adapter.js';
13
+ export { createFjellFsProvider } from './storage/fjell/fs-provider.js';
14
+ export { FjellGcsAdapter } from './storage/fjell/gcs-adapter.js';
15
+ export { createFjellGcsProvider } from './storage/fjell/gcs-provider.js';
10
16
  export { generateUniqueId, slugify } from './api/slug.js';
11
17
  export { createContext } from './api/context.js';
12
18
  export { createTypedAPI } from './api/builder.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,35 @@
1
+ import { EntityFilter } from '../interface';
2
+ import { FjellBackendAdapter, FjellFsProviderConfig } from './types';
3
+ type RawRecord = Record<string, unknown>;
4
+ /**
5
+ * Filesystem-backed Fjell adapter.
6
+ * Uses one lib-fs Library instance per namespace/type pair.
7
+ */
8
+ export declare class FjellFsAdapter implements FjellBackendAdapter {
9
+ private readonly libraries;
10
+ private readonly config;
11
+ private readonly defaultNamespace;
12
+ private initialized;
13
+ constructor(config: FjellFsProviderConfig);
14
+ initialize(): Promise<void>;
15
+ dispose(): Promise<void>;
16
+ isAvailable(): Promise<boolean>;
17
+ get(type: string, id: string, namespace?: string): Promise<RawRecord | undefined>;
18
+ getAll(type: string, namespace?: string): Promise<RawRecord[]>;
19
+ create(type: string, item: RawRecord, namespace?: string): Promise<RawRecord>;
20
+ update(type: string, id: string, item: RawRecord, namespace?: string): Promise<RawRecord>;
21
+ remove(type: string, id: string, namespace?: string): Promise<boolean>;
22
+ find(type: string, filter: EntityFilter, namespace?: string): Promise<RawRecord[]>;
23
+ exists(type: string, id: string, namespace?: string): Promise<boolean>;
24
+ count(type: string, filter?: EntityFilter, namespace?: string): Promise<number>;
25
+ listNamespaces(): Promise<string[]>;
26
+ namespaceExists(namespace: string): Promise<boolean>;
27
+ listTypes(namespace?: string): Promise<string[]>;
28
+ private libraryKey;
29
+ private resolveNamespace;
30
+ private getLibrary;
31
+ private toPriKey;
32
+ private toFjellItem;
33
+ private normalizeFromFjell;
34
+ }
35
+ export {};
@@ -0,0 +1,212 @@
1
+ import * as fs from 'node:fs/promises';
2
+ import * as path from 'node:path';
3
+ import { createPrimaryFilesystemLibrary } from '@fjell/lib-fs';
4
+
5
+ function _define_property(obj, key, value) {
6
+ if (key in obj) {
7
+ Object.defineProperty(obj, key, {
8
+ value: value,
9
+ enumerable: true,
10
+ configurable: true,
11
+ writable: true
12
+ });
13
+ } else {
14
+ obj[key] = value;
15
+ }
16
+ return obj;
17
+ }
18
+ /**
19
+ * Filesystem-backed Fjell adapter.
20
+ * Uses one lib-fs Library instance per namespace/type pair.
21
+ */ class FjellFsAdapter {
22
+ async initialize() {
23
+ await fs.mkdir(this.config.basePath, {
24
+ recursive: true
25
+ });
26
+ // Prime libraries for known types in the default namespace.
27
+ for (const type of this.config.registry.types()){
28
+ this.getLibrary(type);
29
+ }
30
+ this.initialized = true;
31
+ }
32
+ async dispose() {
33
+ this.libraries.clear();
34
+ this.initialized = false;
35
+ }
36
+ async isAvailable() {
37
+ if (!this.initialized) {
38
+ return false;
39
+ }
40
+ try {
41
+ const stat = await fs.stat(this.config.basePath);
42
+ return stat.isDirectory();
43
+ } catch {
44
+ return false;
45
+ }
46
+ }
47
+ async get(type, id, namespace) {
48
+ const library = this.getLibrary(type, namespace);
49
+ const key = this.toPriKey(type, id);
50
+ const item = await library.operations.get(key);
51
+ if (!item) {
52
+ return undefined;
53
+ }
54
+ return this.normalizeFromFjell(item, type, id);
55
+ }
56
+ async getAll(type, namespace) {
57
+ const library = this.getLibrary(type, namespace);
58
+ const result = await library.operations.all();
59
+ return result.items.map((item)=>this.normalizeFromFjell(item, type));
60
+ }
61
+ async create(type, item, namespace) {
62
+ var _item_id;
63
+ const id = String((_item_id = item.id) !== null && _item_id !== void 0 ? _item_id : '');
64
+ const library = this.getLibrary(type, namespace);
65
+ const key = this.toPriKey(type, id);
66
+ const created = await library.operations.create(this.toFjellItem(type, id, item), {
67
+ key
68
+ });
69
+ return this.normalizeFromFjell(created, type, id);
70
+ }
71
+ async update(type, id, item, namespace) {
72
+ const library = this.getLibrary(type, namespace);
73
+ const key = this.toPriKey(type, id);
74
+ const updated = await library.operations.update(key, this.toFjellItem(type, id, item));
75
+ return this.normalizeFromFjell(updated, type, id);
76
+ }
77
+ async remove(type, id, namespace) {
78
+ const existing = await this.get(type, id, namespace);
79
+ if (!existing) {
80
+ return false;
81
+ }
82
+ const library = this.getLibrary(type, namespace);
83
+ const key = this.toPriKey(type, id);
84
+ await library.operations.remove(key);
85
+ return true;
86
+ }
87
+ async find(type, filter, namespace) {
88
+ let results = await this.getAll(type, namespace);
89
+ if (filter.ids && filter.ids.length > 0) {
90
+ const ids = new Set(filter.ids);
91
+ results = results.filter((item)=>ids.has(String(item.id)));
92
+ }
93
+ if (filter.search) {
94
+ const search = filter.search.toLowerCase();
95
+ results = results.filter((item)=>{
96
+ var _item_name, _item_notes;
97
+ const name = String((_item_name = item.name) !== null && _item_name !== void 0 ? _item_name : '').toLowerCase();
98
+ const notes = String((_item_notes = item.notes) !== null && _item_notes !== void 0 ? _item_notes : '').toLowerCase();
99
+ return name.includes(search) || notes.includes(search);
100
+ });
101
+ }
102
+ if (filter.offset && filter.offset > 0) {
103
+ results = results.slice(filter.offset);
104
+ }
105
+ if (filter.limit && filter.limit >= 0) {
106
+ results = results.slice(0, filter.limit);
107
+ }
108
+ return results;
109
+ }
110
+ async exists(type, id, namespace) {
111
+ const existing = await this.get(type, id, namespace);
112
+ return Boolean(existing);
113
+ }
114
+ async count(type, filter, namespace) {
115
+ if (!filter) {
116
+ const all = await this.getAll(type, namespace);
117
+ return all.length;
118
+ }
119
+ const results = await this.find(type, filter, namespace);
120
+ return results.length;
121
+ }
122
+ async listNamespaces() {
123
+ let entries;
124
+ try {
125
+ entries = await fs.readdir(this.config.basePath, {
126
+ withFileTypes: true
127
+ });
128
+ } catch {
129
+ return [];
130
+ }
131
+ const knownTypes = new Set(this.config.registry.types());
132
+ return entries.filter((entry)=>entry.isDirectory()).map((entry)=>entry.name).filter((name)=>!knownTypes.has(name));
133
+ }
134
+ async namespaceExists(namespace) {
135
+ const nsPath = path.join(this.config.basePath, namespace);
136
+ try {
137
+ const stat = await fs.stat(nsPath);
138
+ return stat.isDirectory();
139
+ } catch {
140
+ return false;
141
+ }
142
+ }
143
+ async listTypes(namespace) {
144
+ const ns = this.resolveNamespace(namespace);
145
+ const nsPath = path.join(this.config.basePath, ns);
146
+ let entries;
147
+ try {
148
+ entries = await fs.readdir(nsPath, {
149
+ withFileTypes: true
150
+ });
151
+ } catch {
152
+ return [];
153
+ }
154
+ return entries.filter((entry)=>entry.isDirectory()).map((entry)=>entry.name);
155
+ }
156
+ libraryKey(type, namespace) {
157
+ return `${this.resolveNamespace(namespace)}:${type}`;
158
+ }
159
+ resolveNamespace(namespace) {
160
+ return namespace !== null && namespace !== void 0 ? namespace : this.defaultNamespace;
161
+ }
162
+ getLibrary(type, namespace) {
163
+ const key = this.libraryKey(type, namespace);
164
+ const existing = this.libraries.get(key);
165
+ if (existing) {
166
+ return existing;
167
+ }
168
+ const ns = this.resolveNamespace(namespace);
169
+ const library = createPrimaryFilesystemLibrary(type, `${ns}/${type}`, this.config.basePath);
170
+ this.libraries.set(key, library);
171
+ return library;
172
+ }
173
+ toPriKey(type, id) {
174
+ return {
175
+ kt: type,
176
+ pk: id
177
+ };
178
+ }
179
+ toFjellItem(type, id, item) {
180
+ return {
181
+ ...item,
182
+ id,
183
+ type
184
+ };
185
+ }
186
+ normalizeFromFjell(item, type, idFromKey) {
187
+ const raw = {
188
+ ...item
189
+ };
190
+ delete raw.key;
191
+ delete raw.events;
192
+ delete raw.aggs;
193
+ delete raw.refs;
194
+ const key = item.key;
195
+ const id = idFromKey !== null && idFromKey !== void 0 ? idFromKey : typeof raw.id === 'string' ? raw.id : key === null || key === void 0 ? void 0 : key.pk;
196
+ return {
197
+ ...raw,
198
+ id: id ? String(id) : '',
199
+ type: typeof raw.type === 'string' ? raw.type : type
200
+ };
201
+ }
202
+ constructor(config){
203
+ _define_property(this, "libraries", new Map());
204
+ _define_property(this, "config", void 0);
205
+ _define_property(this, "defaultNamespace", 'default');
206
+ _define_property(this, "initialized", false);
207
+ this.config = config;
208
+ }
209
+ }
210
+
211
+ export { FjellFsAdapter };
212
+ //# sourceMappingURL=fs-adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fs-adapter.js","sources":["../../../src/storage/fjell/fs-adapter.ts"],"sourcesContent":["import * as fs from 'node:fs/promises';\nimport type { Dirent } from 'node:fs';\nimport * as path from 'node:path';\n\nimport { createPrimaryFilesystemLibrary } from '@fjell/lib-fs';\nimport type { FilesystemLibrary } from '@fjell/lib-fs';\nimport type { EntityFilter } from '../interface';\nimport type { FjellBackendAdapter, FjellFsProviderConfig } from './types';\n\ntype RawRecord = Record<string, unknown>;\n\n/**\n * Filesystem-backed Fjell adapter.\n * Uses one lib-fs Library instance per namespace/type pair.\n */\nexport class FjellFsAdapter implements FjellBackendAdapter {\n private readonly libraries = new Map<string, FilesystemLibrary<any, string>>();\n private readonly config: FjellFsProviderConfig;\n private readonly defaultNamespace = 'default';\n private initialized = false;\n\n constructor(config: FjellFsProviderConfig) {\n this.config = config;\n }\n\n async initialize(): Promise<void> {\n await fs.mkdir(this.config.basePath, { recursive: true });\n // Prime libraries for known types in the default namespace.\n for (const type of this.config.registry.types()) {\n this.getLibrary(type);\n }\n this.initialized = true;\n }\n\n async dispose(): Promise<void> {\n this.libraries.clear();\n this.initialized = false;\n }\n\n async isAvailable(): Promise<boolean> {\n if (!this.initialized) {\n return false;\n }\n try {\n const stat = await fs.stat(this.config.basePath);\n return stat.isDirectory();\n } catch {\n return false;\n }\n }\n\n async get(type: string, id: string, namespace?: string): Promise<RawRecord | undefined> {\n const library = this.getLibrary(type, namespace);\n const key = this.toPriKey(type, id);\n const item = await library.operations.get(key);\n if (!item) {\n return undefined;\n }\n return this.normalizeFromFjell(item as RawRecord, type, id);\n }\n\n async getAll(type: string, namespace?: string): Promise<RawRecord[]> {\n const library = this.getLibrary(type, namespace);\n const result = await library.operations.all();\n return result.items.map(item => this.normalizeFromFjell(item as RawRecord, type));\n }\n\n async create(type: string, item: RawRecord, namespace?: string): Promise<RawRecord> {\n const id = String(item.id ?? '');\n const library = this.getLibrary(type, namespace);\n const key = this.toPriKey(type, id);\n const created = await library.operations.create(this.toFjellItem(type, id, item), { key });\n return this.normalizeFromFjell(created as RawRecord, type, id);\n }\n\n async update(type: string, id: string, item: RawRecord, namespace?: string): Promise<RawRecord> {\n const library = this.getLibrary(type, namespace);\n const key = this.toPriKey(type, id);\n const updated = await library.operations.update(key, this.toFjellItem(type, id, item));\n return this.normalizeFromFjell(updated as RawRecord, type, id);\n }\n\n async remove(type: string, id: string, namespace?: string): Promise<boolean> {\n const existing = await this.get(type, id, namespace);\n if (!existing) {\n return false;\n }\n const library = this.getLibrary(type, namespace);\n const key = this.toPriKey(type, id);\n await library.operations.remove(key);\n return true;\n }\n\n async find(type: string, filter: EntityFilter, namespace?: string): Promise<RawRecord[]> {\n let results = await this.getAll(type, namespace);\n\n if (filter.ids && filter.ids.length > 0) {\n const ids = new Set(filter.ids);\n results = results.filter(item => ids.has(String(item.id)));\n }\n\n if (filter.search) {\n const search = filter.search.toLowerCase();\n results = results.filter(item => {\n const name = String(item.name ?? '').toLowerCase();\n const notes = String(item.notes ?? '').toLowerCase();\n return name.includes(search) || notes.includes(search);\n });\n }\n\n if (filter.offset && filter.offset > 0) {\n results = results.slice(filter.offset);\n }\n\n if (filter.limit && filter.limit >= 0) {\n results = results.slice(0, filter.limit);\n }\n\n return results;\n }\n\n async exists(type: string, id: string, namespace?: string): Promise<boolean> {\n const existing = await this.get(type, id, namespace);\n return Boolean(existing);\n }\n\n async count(type: string, filter?: EntityFilter, namespace?: string): Promise<number> {\n if (!filter) {\n const all = await this.getAll(type, namespace);\n return all.length;\n }\n const results = await this.find(type, filter, namespace);\n return results.length;\n }\n\n async listNamespaces(): Promise<string[]> {\n let entries: Dirent[];\n try {\n entries = await fs.readdir(this.config.basePath, { withFileTypes: true });\n } catch {\n return [];\n }\n\n const knownTypes = new Set(this.config.registry.types());\n return entries\n .filter(entry => entry.isDirectory())\n .map(entry => entry.name)\n .filter(name => !knownTypes.has(name));\n }\n\n async namespaceExists(namespace: string): Promise<boolean> {\n const nsPath = path.join(this.config.basePath, namespace);\n try {\n const stat = await fs.stat(nsPath);\n return stat.isDirectory();\n } catch {\n return false;\n }\n }\n\n async listTypes(namespace?: string): Promise<string[]> {\n const ns = this.resolveNamespace(namespace);\n const nsPath = path.join(this.config.basePath, ns);\n let entries: Dirent[];\n try {\n entries = await fs.readdir(nsPath, { withFileTypes: true });\n } catch {\n return [];\n }\n\n return entries\n .filter(entry => entry.isDirectory())\n .map(entry => entry.name);\n }\n\n private libraryKey(type: string, namespace?: string): string {\n return `${this.resolveNamespace(namespace)}:${type}`;\n }\n\n private resolveNamespace(namespace?: string): string {\n return namespace ?? this.defaultNamespace;\n }\n\n private getLibrary(type: string, namespace?: string): FilesystemLibrary<any, string> {\n const key = this.libraryKey(type, namespace);\n const existing = this.libraries.get(key);\n if (existing) {\n return existing;\n }\n\n const ns = this.resolveNamespace(namespace);\n const library = createPrimaryFilesystemLibrary(type, `${ns}/${type}`, this.config.basePath);\n this.libraries.set(key, library);\n return library;\n }\n\n private toPriKey(type: string, id: string): { kt: string; pk: string } {\n return { kt: type, pk: id };\n }\n\n private toFjellItem(type: string, id: string, item: RawRecord): RawRecord {\n return {\n ...item,\n id,\n type,\n };\n }\n\n private normalizeFromFjell(item: RawRecord, type: string, idFromKey?: string): RawRecord {\n const raw = { ...item };\n delete raw.key;\n delete raw.events;\n delete raw.aggs;\n delete raw.refs;\n\n const key = item.key as { pk?: string | number } | undefined;\n const id = idFromKey ?? (typeof raw.id === 'string' ? raw.id : key?.pk);\n\n return {\n ...raw,\n id: id ? String(id) : '',\n type: (typeof raw.type === 'string' ? raw.type : type),\n };\n }\n}\n"],"names":["FjellFsAdapter","initialize","fs","mkdir","config","basePath","recursive","type","registry","types","getLibrary","initialized","dispose","libraries","clear","isAvailable","stat","isDirectory","get","id","namespace","library","key","toPriKey","item","operations","undefined","normalizeFromFjell","getAll","result","all","items","map","create","String","created","toFjellItem","update","updated","remove","existing","find","filter","results","ids","length","Set","has","search","toLowerCase","name","notes","includes","offset","slice","limit","exists","Boolean","count","listNamespaces","entries","readdir","withFileTypes","knownTypes","entry","namespaceExists","nsPath","path","join","listTypes","ns","resolveNamespace","libraryKey","defaultNamespace","createPrimaryFilesystemLibrary","set","kt","pk","idFromKey","raw","events","aggs","refs","Map"],"mappings":";;;;;;;;;;;;;;;;;AAWA;;;AAGC,IACM,MAAMA,cAAAA,CAAAA;AAUT,IAAA,MAAMC,UAAAA,GAA4B;QAC9B,MAAMC,EAAAA,CAAGC,KAAK,CAAC,IAAI,CAACC,MAAM,CAACC,QAAQ,EAAE;YAAEC,SAAAA,EAAW;AAAK,SAAA,CAAA;;QAEvD,KAAK,MAAMC,QAAQ,IAAI,CAACH,MAAM,CAACI,QAAQ,CAACC,KAAK,EAAA,CAAI;YAC7C,IAAI,CAACC,UAAU,CAACH,IAAAA,CAAAA;A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AE,GAAGG,GAAAA,KAAAA,IAAAA,IAAAA,GAAAA,KAAAA,MAAAA,GAAAA,MAAAA,GAAAA,IAAKuD,EAAE;QAEtE,OAAO;AACH,YAAA,GAAGE,GAAG;YACN5D,EAAAA,EAAIA,EAAAA,GAAKe,OAAOf,EAAAA,CAAAA,GAAM,EAAA;AACtBZ,YAAAA,IAAAA,EAAO,OAAOwE,GAAAA,CAAIxE,IAAI,KAAK,QAAA,GAAWwE,GAAAA,CAAIxE,IAAI,GAAGA;AACrD,SAAA;AACJ,IAAA;AA1MA,IAAA,WAAA,CAAYH,MAA6B,CAAE;AAL3C,QAAA,gBAAA,CAAA,IAAA,EAAiBS,aAAY,IAAIsE,GAAAA,EAAAA,CAAAA;AACjC,QAAA,gBAAA,CAAA,IAAA,EAAiB/E,UAAjB,MAAA,CAAA;AACA,QAAA,gBAAA,CAAA,IAAA,EAAiBqE,kBAAAA,EAAmB,SAAA,CAAA;AACpC,QAAA,gBAAA,CAAA,IAAA,EAAQ9D,aAAAA,EAAc,KAAA,CAAA;QAGlB,IAAI,CAACP,MAAM,GAAGA,MAAAA;AAClB,IAAA;AAyMJ;;;;"}
@@ -0,0 +1,3 @@
1
+ import { StorageProvider } from '../interface';
2
+ import { FjellFsProviderConfig } from './types';
3
+ export declare function createFjellFsProvider(config: FjellFsProviderConfig): Promise<StorageProvider>;
@@ -0,0 +1,13 @@
1
+ import { FjellStorageProvider } from './provider.js';
2
+ import { FjellFsAdapter } from './fs-adapter.js';
3
+
4
+ async function createFjellFsProvider(config) {
5
+ var _config_name;
6
+ const adapter = new FjellFsAdapter(config);
7
+ const provider = new FjellStorageProvider(adapter, config.registry, (_config_name = config.name) !== null && _config_name !== void 0 ? _config_name : 'fjell-fs', config.basePath);
8
+ await provider.initialize();
9
+ return provider;
10
+ }
11
+
12
+ export { createFjellFsProvider };
13
+ //# sourceMappingURL=fs-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fs-provider.js","sources":["../../../src/storage/fjell/fs-provider.ts"],"sourcesContent":["import type { StorageProvider } from '../interface';\nimport { FjellStorageProvider } from './provider';\nimport { FjellFsAdapter } from './fs-adapter';\nimport type { FjellFsProviderConfig } from './types';\n\nexport async function createFjellFsProvider(config: FjellFsProviderConfig): Promise<StorageProvider> {\n const adapter = new FjellFsAdapter(config);\n const provider = new FjellStorageProvider(\n adapter,\n config.registry,\n config.name ?? 'fjell-fs',\n config.basePath,\n );\n await provider.initialize();\n return provider;\n}\n"],"names":["createFjellFsProvider","config","adapter","FjellFsAdapter","provider","FjellStorageProvider","registry","name","basePath","initialize"],"mappings":";;;AAKO,eAAeA,sBAAsBC,MAA6B,EAAA;AAKjEA,IAAAA,IAAAA,YAAAA;IAJJ,MAAMC,OAAAA,GAAU,IAAIC,cAAAA,CAAeF,MAAAA,CAAAA;AACnC,IAAA,MAAMG,QAAAA,GAAW,IAAIC,oBAAAA,CACjBH,OAAAA,EACAD,OAAOK,QAAQ,EAAA,CACfL,YAAAA,GAAAA,MAAAA,CAAOM,IAAI,MAAA,IAAA,IAAXN,YAAAA,KAAAA,MAAAA,GAAAA,YAAAA,GAAe,UAAA,EACfA,OAAOO,QAAQ,CAAA;AAEnB,IAAA,MAAMJ,SAASK,UAAU,EAAA;IACzB,OAAOL,QAAAA;AACX;;;;"}
@@ -0,0 +1,40 @@
1
+ import { EntityFilter } from '../interface';
2
+ import { FjellBackendAdapter, FjellGcsProviderConfig } from './types';
3
+ type RawRecord = Record<string, unknown>;
4
+ /**
5
+ * GCS-backed Fjell adapter.
6
+ * Uses one lib-gcs Library instance per namespace/type pair.
7
+ */
8
+ export declare class FjellGcsAdapter implements FjellBackendAdapter {
9
+ private readonly libraries;
10
+ private readonly config;
11
+ private readonly defaultNamespace;
12
+ private initialized;
13
+ constructor(config: FjellGcsProviderConfig);
14
+ initialize(): Promise<void>;
15
+ dispose(): Promise<void>;
16
+ isAvailable(): Promise<boolean>;
17
+ get(type: string, id: string, namespace?: string): Promise<RawRecord | undefined>;
18
+ getAll(type: string, namespace?: string): Promise<RawRecord[]>;
19
+ create(type: string, item: RawRecord, namespace?: string): Promise<RawRecord>;
20
+ update(type: string, id: string, item: RawRecord, namespace?: string): Promise<RawRecord>;
21
+ remove(type: string, id: string, namespace?: string): Promise<boolean>;
22
+ find(type: string, filter: EntityFilter, namespace?: string): Promise<RawRecord[]>;
23
+ exists(type: string, id: string, namespace?: string): Promise<boolean>;
24
+ count(type: string, filter?: EntityFilter, namespace?: string): Promise<number>;
25
+ listNamespaces(): Promise<string[]>;
26
+ namespaceExists(namespace: string): Promise<boolean>;
27
+ listTypes(namespace?: string): Promise<string[]>;
28
+ private libraryKey;
29
+ private resolveNamespace;
30
+ private getLibrary;
31
+ private toPriKey;
32
+ private toFjellItem;
33
+ private normalizeFromFjell;
34
+ private objectPrefix;
35
+ private joinPath;
36
+ private normalizeBasePath;
37
+ private relativeObjectPath;
38
+ private listObjectNames;
39
+ }
40
+ export {};
@@ -0,0 +1,249 @@
1
+ import { createPrimaryGCSLibrary } from '@fjell/lib-gcs';
2
+
3
+ function _define_property(obj, key, value) {
4
+ if (key in obj) {
5
+ Object.defineProperty(obj, key, {
6
+ value: value,
7
+ enumerable: true,
8
+ configurable: true,
9
+ writable: true
10
+ });
11
+ } else {
12
+ obj[key] = value;
13
+ }
14
+ return obj;
15
+ }
16
+ /**
17
+ * GCS-backed Fjell adapter.
18
+ * Uses one lib-gcs Library instance per namespace/type pair.
19
+ */ class FjellGcsAdapter {
20
+ async initialize() {
21
+ // Prime libraries for known types in the default namespace.
22
+ for (const type of this.config.registry.types()){
23
+ this.getLibrary(type);
24
+ }
25
+ this.initialized = true;
26
+ }
27
+ async dispose() {
28
+ this.libraries.clear();
29
+ this.initialized = false;
30
+ }
31
+ async isAvailable() {
32
+ return this.initialized;
33
+ }
34
+ async get(type, id, namespace) {
35
+ const library = this.getLibrary(type, namespace);
36
+ const key = this.toPriKey(type, id);
37
+ const item = await library.operations.get(key);
38
+ if (!item) {
39
+ return undefined;
40
+ }
41
+ return this.normalizeFromFjell(item, type, id);
42
+ }
43
+ async getAll(type, namespace) {
44
+ const library = this.getLibrary(type, namespace);
45
+ const result = await library.operations.all();
46
+ return result.items.map((item)=>this.normalizeFromFjell(item, type));
47
+ }
48
+ async create(type, item, namespace) {
49
+ var _item_id;
50
+ const id = String((_item_id = item.id) !== null && _item_id !== void 0 ? _item_id : '');
51
+ const library = this.getLibrary(type, namespace);
52
+ const key = this.toPriKey(type, id);
53
+ const created = await library.operations.create(this.toFjellItem(type, id, item), {
54
+ key
55
+ });
56
+ return this.normalizeFromFjell(created, type, id);
57
+ }
58
+ async update(type, id, item, namespace) {
59
+ const library = this.getLibrary(type, namespace);
60
+ const key = this.toPriKey(type, id);
61
+ const updated = await library.operations.update(key, this.toFjellItem(type, id, item));
62
+ return this.normalizeFromFjell(updated, type, id);
63
+ }
64
+ async remove(type, id, namespace) {
65
+ const existing = await this.get(type, id, namespace);
66
+ if (!existing) {
67
+ return false;
68
+ }
69
+ const library = this.getLibrary(type, namespace);
70
+ const key = this.toPriKey(type, id);
71
+ await library.operations.remove(key);
72
+ return true;
73
+ }
74
+ async find(type, filter, namespace) {
75
+ let results = await this.getAll(type, namespace);
76
+ if (filter.ids && filter.ids.length > 0) {
77
+ const ids = new Set(filter.ids);
78
+ results = results.filter((item)=>ids.has(String(item.id)));
79
+ }
80
+ if (filter.search) {
81
+ const search = filter.search.toLowerCase();
82
+ results = results.filter((item)=>{
83
+ var _item_name, _item_notes;
84
+ const name = String((_item_name = item.name) !== null && _item_name !== void 0 ? _item_name : '').toLowerCase();
85
+ const notes = String((_item_notes = item.notes) !== null && _item_notes !== void 0 ? _item_notes : '').toLowerCase();
86
+ return name.includes(search) || notes.includes(search);
87
+ });
88
+ }
89
+ if (filter.offset && filter.offset > 0) {
90
+ results = results.slice(filter.offset);
91
+ }
92
+ if (filter.limit && filter.limit >= 0) {
93
+ results = results.slice(0, filter.limit);
94
+ }
95
+ return results;
96
+ }
97
+ async exists(type, id, namespace) {
98
+ const existing = await this.get(type, id, namespace);
99
+ return Boolean(existing);
100
+ }
101
+ async count(type, filter, namespace) {
102
+ if (!filter) {
103
+ const all = await this.getAll(type, namespace);
104
+ return all.length;
105
+ }
106
+ const results = await this.find(type, filter, namespace);
107
+ return results.length;
108
+ }
109
+ async listNamespaces() {
110
+ const names = await this.listObjectNames(this.objectPrefix());
111
+ const knownTypes = new Set(this.config.registry.types());
112
+ const namespaces = new Set();
113
+ for (const name of names){
114
+ const rel = this.relativeObjectPath(name);
115
+ if (!rel) {
116
+ continue;
117
+ }
118
+ const [firstSegment] = rel.split('/');
119
+ if (!firstSegment || knownTypes.has(firstSegment)) {
120
+ continue;
121
+ }
122
+ namespaces.add(firstSegment);
123
+ }
124
+ return Array.from(namespaces);
125
+ }
126
+ async namespaceExists(namespace) {
127
+ const prefix = this.objectPrefix(namespace);
128
+ const names = await this.listObjectNames(prefix);
129
+ return names.length > 0;
130
+ }
131
+ async listTypes(namespace) {
132
+ const ns = this.resolveNamespace(namespace);
133
+ const prefix = this.objectPrefix(ns);
134
+ const names = await this.listObjectNames(prefix);
135
+ const types = new Set();
136
+ for (const name of names){
137
+ const rel = this.relativeObjectPath(name);
138
+ if (!rel || !rel.startsWith(`${ns}/`)) {
139
+ continue;
140
+ }
141
+ const parts = rel.split('/');
142
+ if (parts.length >= 2 && parts[1]) {
143
+ types.add(parts[1]);
144
+ }
145
+ }
146
+ return Array.from(types);
147
+ }
148
+ libraryKey(type, namespace) {
149
+ return `${this.resolveNamespace(namespace)}:${type}`;
150
+ }
151
+ resolveNamespace(namespace) {
152
+ return namespace !== null && namespace !== void 0 ? namespace : this.defaultNamespace;
153
+ }
154
+ getLibrary(type, namespace) {
155
+ const key = this.libraryKey(type, namespace);
156
+ const existing = this.libraries.get(key);
157
+ if (existing) {
158
+ return existing;
159
+ }
160
+ const ns = this.resolveNamespace(namespace);
161
+ const libBasePath = this.joinPath(this.normalizeBasePath(this.config.basePath), ns);
162
+ const library = createPrimaryGCSLibrary(type, type, {
163
+ bucketName: this.config.bucketName,
164
+ basePath: libBasePath,
165
+ storage: this.config.storage,
166
+ useJsonExtension: true,
167
+ querySafety: this.config.querySafety
168
+ });
169
+ this.libraries.set(key, library);
170
+ return library;
171
+ }
172
+ toPriKey(type, id) {
173
+ return {
174
+ kt: type,
175
+ pk: id
176
+ };
177
+ }
178
+ toFjellItem(type, id, item) {
179
+ return {
180
+ ...item,
181
+ id,
182
+ type
183
+ };
184
+ }
185
+ normalizeFromFjell(item, type, idFromKey) {
186
+ const raw = {
187
+ ...item
188
+ };
189
+ delete raw.key;
190
+ delete raw.events;
191
+ delete raw.aggs;
192
+ delete raw.refs;
193
+ const key = item.key;
194
+ const id = idFromKey !== null && idFromKey !== void 0 ? idFromKey : typeof raw.id === 'string' ? raw.id : key === null || key === void 0 ? void 0 : key.pk;
195
+ return {
196
+ ...raw,
197
+ id: id ? String(id) : '',
198
+ type: typeof raw.type === 'string' ? raw.type : type
199
+ };
200
+ }
201
+ objectPrefix(...parts) {
202
+ const normalizedBase = this.normalizeBasePath(this.config.basePath);
203
+ const segments = [
204
+ normalizedBase,
205
+ ...parts
206
+ ].filter(Boolean);
207
+ return segments.length > 0 ? `${segments.join('/')}/` : '';
208
+ }
209
+ joinPath(...parts) {
210
+ return parts.filter(Boolean).join('/');
211
+ }
212
+ normalizeBasePath(basePath) {
213
+ if (!basePath) {
214
+ return '';
215
+ }
216
+ return basePath.replace(/^\/+|\/+$/g, '');
217
+ }
218
+ relativeObjectPath(fullName) {
219
+ const base = this.normalizeBasePath(this.config.basePath);
220
+ if (!base) {
221
+ return fullName;
222
+ }
223
+ return fullName.startsWith(`${base}/`) ? fullName.slice(base.length + 1) : fullName;
224
+ }
225
+ async listObjectNames(prefix) {
226
+ const storage = this.config.storage;
227
+ if (!storage) {
228
+ return [];
229
+ }
230
+ const bucket = storage.bucket(this.config.bucketName);
231
+ const [files] = await bucket.getFiles({
232
+ prefix
233
+ });
234
+ return files.map((file)=>{
235
+ var _file_name;
236
+ return (_file_name = file.name) !== null && _file_name !== void 0 ? _file_name : '';
237
+ }).filter(Boolean);
238
+ }
239
+ constructor(config){
240
+ _define_property(this, "libraries", new Map());
241
+ _define_property(this, "config", void 0);
242
+ _define_property(this, "defaultNamespace", 'default');
243
+ _define_property(this, "initialized", false);
244
+ this.config = config;
245
+ }
246
+ }
247
+
248
+ export { FjellGcsAdapter };
249
+ //# sourceMappingURL=gcs-adapter.js.map