@oddington/sdk 0.1.56 → 0.1.58
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,4 +1,4 @@
|
|
|
1
|
-
import type { CollectionSchema, DataRepository, PublicValueDefinition, RecordsQuery, RecordsResult, SelectionMetadata } from '../../../shared/data-contract.js';
|
|
1
|
+
import type { CollectionSchema, DataRepository, DataValue, SnapshotChange, PublicValueDefinition, RecordsQuery, RecordsResult, SelectionMetadata } from '../../../shared/data-contract.js';
|
|
2
2
|
import type { DataRepositorySchemas } from './public.js';
|
|
3
3
|
type ReadonlySchema<Value> = Value extends object ? {
|
|
4
4
|
readonly [Key in keyof Value]: ReadonlySchema<Value[Key]>;
|
|
@@ -185,4 +185,24 @@ type SchemaRepository<Schemas extends Catalogue> = Omit<DataRepository, 'records
|
|
|
185
185
|
};
|
|
186
186
|
/** Generated metadata refines declarations only; unknown aliases stay generic. */
|
|
187
187
|
export type RepositoryFor<Name extends string> = string extends Name ? DataRepository : Name extends keyof DataRepositorySchemas ? DataRepositorySchemas[Name] extends Catalogue ? SchemaRepository<DataRepositorySchemas[Name]> : DataRepository : DataRepository;
|
|
188
|
+
type RecordBuilder<Create, Update, Links> = {
|
|
189
|
+
create<Input extends Create>(fields: Input & Exact<Input, Create>): RecordBuilder<Create, Update, Links>;
|
|
190
|
+
update<Input extends Update>(fields: Input & Exact<Input, Update>): RecordBuilder<Create, Update, Links>;
|
|
191
|
+
link<Input extends Links>(fields: Input & Exact<Input, Links>): RecordBuilder<Create, Update, Links>;
|
|
192
|
+
unlink<Input extends Links>(fields: Input & Exact<Input, Links>): RecordBuilder<Create, Update, Links>;
|
|
193
|
+
delete(): RecordBuilder<Create, Update, Links>;
|
|
194
|
+
};
|
|
195
|
+
type Editable<Schema extends Collection> = Exclude<Fields<Schema>, {
|
|
196
|
+
name: 'id' | 'type';
|
|
197
|
+
}>;
|
|
198
|
+
type SchemaBuilder<Schemas extends Catalogue> = {
|
|
199
|
+
[Schema in Schemas['collections'][number] as Schema['name']]: Record<string, RecordBuilder<ObjectValue<Fields<Schema>>, Partial<ObjectValue<Editable<Schema>>>, {
|
|
200
|
+
[F in Extract<Editable<Schema>, {
|
|
201
|
+
kind: 'link';
|
|
202
|
+
}> as F['name']]?: string | string[];
|
|
203
|
+
}>>;
|
|
204
|
+
};
|
|
205
|
+
type GenericBuilder = Record<string, Record<string, RecordBuilder<Record<string, DataValue>, Record<string, DataValue>, Record<string, string | string[]>>>>;
|
|
206
|
+
export type SnapshotTransaction<Name extends string = string> = string extends Name ? GenericBuilder : Name extends keyof DataRepositorySchemas ? DataRepositorySchemas[Name] extends Catalogue ? SchemaBuilder<DataRepositorySchemas[Name]> : GenericBuilder : GenericBuilder;
|
|
207
|
+
export type SnapshotTransact<Name extends string = string> = <Result>(callback: (tx: SnapshotTransaction<Name>) => Result & (Result extends PromiseLike<unknown> ? never : unknown)) => Promise<SnapshotChange[]>;
|
|
188
208
|
export {};
|
|
@@ -26,12 +26,22 @@ declare global {
|
|
|
26
26
|
/** Reserved for OS-generated snapshots, including legacy module augmentations. */
|
|
27
27
|
export interface DataRepositorySchemas extends __OddingtonOS.DataRepositorySchemas {
|
|
28
28
|
}
|
|
29
|
+
export type { SnapshotTransaction } from './data-schema-types.js';
|
|
29
30
|
export type DataSnapshot<Name extends string = string> = {
|
|
31
|
+
subscribe(listener: (update: {
|
|
32
|
+
records: boolean;
|
|
33
|
+
changes: boolean;
|
|
34
|
+
}) => void): () => void;
|
|
30
35
|
records: Pick<import('./data-schema-types.js').RepositoryFor<Name>['records'], 'query' | 'pages' | 'all'> & {
|
|
31
36
|
read(ref: string): Promise<import('../../../shared/data-contract.js').SelectedRecord | null>;
|
|
32
37
|
};
|
|
38
|
+
transact: import('./data-schema-types.js').SnapshotTransact<Name>;
|
|
33
39
|
changes: {
|
|
34
40
|
list(): Promise<import('../../../shared/data-contract.js').SnapshotChange[]>;
|
|
41
|
+
publish(selected: readonly Pick<import('../../../shared/data-contract.js').SnapshotChange, 'id' | 'version'>[], options?: {
|
|
42
|
+
summary?: string;
|
|
43
|
+
}): Promise<void>;
|
|
44
|
+
discard(selected: readonly Pick<import('../../../shared/data-contract.js').SnapshotChange, 'id' | 'version'>[]): Promise<void>;
|
|
35
45
|
};
|
|
36
46
|
};
|
|
37
47
|
export declare const data: {
|
|
@@ -207,11 +207,24 @@ export type SnapshotChange = {
|
|
|
207
207
|
kind: 'set';
|
|
208
208
|
field: string;
|
|
209
209
|
value: DataValue;
|
|
210
|
+
} | {
|
|
211
|
+
kind: 'link';
|
|
212
|
+
field: string;
|
|
213
|
+
refs: string[];
|
|
214
|
+
remove?: string[];
|
|
215
|
+
} | {
|
|
216
|
+
kind: 'unlink';
|
|
217
|
+
field: string;
|
|
218
|
+
refs: string[];
|
|
210
219
|
} | {
|
|
211
220
|
kind: 'create' | 'delete';
|
|
212
221
|
fields: Record<string, DataValue>;
|
|
213
222
|
};
|
|
214
|
-
|
|
223
|
+
person?: {
|
|
224
|
+
id: string;
|
|
225
|
+
name?: string;
|
|
226
|
+
email?: string;
|
|
227
|
+
};
|
|
215
228
|
source?: {
|
|
216
229
|
kind: 'app' | 'routine';
|
|
217
230
|
id: string;
|