@telepath-computer/autofile 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/store.d.ts CHANGED
@@ -1,132 +1,112 @@
1
1
  /**
2
- * Reads and writes Autofile's on-disk types and records, and exposes recognized
3
- * records, declarations, and blobs as plain resource data. Each operation reads
4
- * current files and keeps protocol-specific behavior outside the store.
2
+ * Autofile owns one data folder: record and type operations, blob uploads and
3
+ * reads, and shared change subscriptions. Operations read current files;
4
+ * protocol adapters translate these values without owning a second persistence
5
+ * implementation.
5
6
  */
6
- import type { JsonObject } from "./json.js";
7
+ import { type JsonObject } from "./json.js";
8
+ import { type PreparedSchema } from "./schema.js";
7
9
  export type { JsonObject, JsonPrimitive, JsonValue } from "./json.js";
8
- export interface StoreError {
10
+ /** One reason an operation was refused, with an address when applicable. */
11
+ export interface AutofileProblem {
9
12
  uri?: string;
10
13
  message: string;
11
14
  }
12
- export interface Refusal {
13
- errors: StoreError[];
15
+ /** A refused operation, with every problem the caller can correct. */
16
+ export declare class AutofileError extends Error {
17
+ readonly problems: AutofileProblem[];
18
+ constructor(problems: AutofileProblem[]);
14
19
  }
15
- export interface OpenStoreOptions {
16
- dataFolder?: string;
17
- writeLockPath?: string;
18
- }
19
- /** Transport-sensitive permissions for a record write. */
20
- export interface RecordWriteOptions {
21
- allowLocalPaths?: boolean;
22
- }
23
- export interface Store {
24
- findRecords(input: FindRecordsInput): Promise<FindRecordsResult | Refusal>;
25
- getRecord(input: GetRecordInput): Promise<RecordResult | Refusal>;
26
- createRecord(input: CreateRecordInput, options?: RecordWriteOptions): Promise<UriResult | Refusal>;
27
- updateRecord(input: UpdateRecordInput, options?: RecordWriteOptions): Promise<UriResult | Refusal>;
28
- deleteRecord(input: DeleteRecordInput): Promise<UriResult | Refusal>;
29
- listTypes(input: Record<string, never>): Promise<ListTypesResult>;
30
- getType(input: GetTypeInput): Promise<TypeResult | Refusal>;
31
- createType(input: CreateTypeInput): Promise<UriResult | Refusal>;
32
- updateType(input: UpdateTypeInput): Promise<UpdateTypeResult | Refusal>;
33
- deleteType(input: DeleteTypeInput): Promise<UriResult | Refusal>;
34
- listResources(): Promise<StoreResource[]>;
35
- getResourceMetadata(uri: string): Promise<StoreResource | undefined>;
36
- listResourceFolder(folder: string): Promise<StoreResource[]>;
37
- listTypeResources(type: string): Promise<StoreResource[]>;
38
- readResource(uri: string): Promise<StoreResourceContents | undefined>;
39
- }
40
- export interface FindRecordsInput {
41
- type: string;
42
- q?: string;
43
- where?: JsonObject;
44
- limit?: number;
45
- fields?: string[];
46
- cursor?: string;
47
- }
48
- export interface GetRecordInput {
20
+ /** A record with its address, identity, and optional display title. */
21
+ export interface AutofileRecord {
49
22
  uri: string;
50
- }
51
- export interface CreateRecordInput {
52
23
  type: string;
53
- key?: string;
54
- record: JsonObject;
55
- }
56
- export interface UpdateRecordInput {
57
- uri: string;
58
- patch: JsonObject;
59
- }
60
- export interface DeleteRecordInput {
61
- uri: string;
62
- }
63
- export interface GetTypeInput {
64
- type: string;
65
- }
66
- export interface CreateTypeInput {
67
- type: string;
68
- description: string;
69
- schema: JsonObject;
70
- titleField?: string;
71
- }
72
- export interface UpdateTypeInput {
73
- type: string;
74
- description?: string;
75
- schema?: JsonObject;
76
- titleField?: string | null;
77
- }
78
- export interface DeleteTypeInput {
79
- type: string;
80
- }
81
- export interface UriResult {
82
- uri: string;
83
- }
84
- export interface FindRecordsResult {
85
- records: RecordResult[];
86
- errors: StoreError[];
87
- cursor?: string;
88
- }
89
- export interface RecordResult extends UriResult {
24
+ key: string;
25
+ title?: string;
26
+ problems?: AutofileProblem[];
90
27
  createdAt: string;
91
28
  updatedAt: string;
92
29
  value: JsonObject;
93
- error?: string;
94
30
  }
95
- export interface TypeSummary extends UriResult {
96
- type: string;
97
- description: string;
31
+ /** Optional filters and paging controls; where and fields apply only to value. */
32
+ export interface RecordQuery {
33
+ type?: string | string[];
34
+ q?: string;
35
+ where?: JsonObject;
36
+ fields?: string[];
37
+ limit?: number;
38
+ cursor?: string;
98
39
  }
99
- export interface ListTypesResult {
100
- types: TypeSummary[];
40
+ /** One page of matching records and records that could not be returned. */
41
+ export interface RecordQueryResult {
42
+ records: AutofileRecord[];
43
+ unreadable: {
44
+ uri: string;
45
+ message: string;
46
+ }[];
47
+ cursor?: string;
101
48
  }
102
- export interface TypeResult extends UriResult {
49
+ /** The fields stored in a type declaration. */
50
+ export interface TypeDefinition {
103
51
  description: string;
104
52
  schema: JsonObject;
105
53
  titleField?: string;
106
- }
107
- export interface UpdateTypeResult extends UriResult {
108
- errors: StoreError[];
109
- }
110
- /** Plain metadata for one resource recognized in the data folder. */
111
- export interface StoreResource extends UriResult {
112
- name: string;
113
- mimeType: string;
114
54
  title?: string;
115
- description?: string;
116
- size?: number;
117
- lastModified?: string;
118
55
  }
119
- /** Exact contents of a recognized text or binary resource. */
120
- export type StoreResourceContents = {
56
+ /** A type declaration together with its name and address. */
57
+ export interface TypeDeclaration extends TypeDefinition {
121
58
  uri: string;
122
- mimeType: string;
123
- text: string;
124
- } | {
125
- uri: string;
126
- mimeType: string;
127
- blob: string;
59
+ type: string;
60
+ problems?: AutofileProblem[];
61
+ }
62
+ /** Changes to a declaration; null removes the title or title field. */
63
+ export type TypeChanges = Partial<Omit<TypeDefinition, "titleField" | "title">> & {
64
+ titleField?: string | null;
65
+ title?: string | null;
128
66
  };
129
- /** Opens a store, creating its data folder when it does not exist. */
130
- export declare function openStore(options?: OpenStoreOptions): Promise<Store>;
131
- /** Returns whether a string is the canonical URI of an Autofile resource. */
132
- export declare function isResourceUri(uri: string): boolean;
67
+ /** A record or type was created, changed, or deleted. */
68
+ export interface ChangeEvent {
69
+ uri: string;
70
+ kind: "created" | "changed" | "deleted";
71
+ }
72
+ type ChangeListener = (changes: ChangeEvent[]) => void | Promise<void>;
73
+ /** Handles failures from this subscription or from change monitoring. */
74
+ export interface WatchOptions {
75
+ onError?: (error: Error) => void;
76
+ }
77
+ /** The store implementation. Construction resolves paths but performs no I/O. */
78
+ export declare class Autofile {
79
+ #private;
80
+ constructor(options: {
81
+ folder: string;
82
+ });
83
+ readonly records: {
84
+ find: (query?: RecordQuery) => Promise<RecordQueryResult>;
85
+ get: (uri: string) => Promise<AutofileRecord | undefined>;
86
+ create: (type: string, value: JsonObject, options?: {
87
+ key?: string;
88
+ }) => Promise<AutofileRecord>;
89
+ update: (uri: string, patch: JsonObject) => Promise<AutofileRecord>;
90
+ delete: (uri: string) => Promise<void>;
91
+ };
92
+ readonly types: {
93
+ list: () => Promise<TypeDeclaration[]>;
94
+ get: (name: string) => Promise<TypeDeclaration | undefined>;
95
+ create: (name: string, definition: TypeDefinition) => Promise<TypeDeclaration>;
96
+ update: (name: string, changes: TypeChanges) => Promise<TypeDeclaration>;
97
+ delete: (name: string) => Promise<void>;
98
+ };
99
+ readonly blobs: {
100
+ put: (bytes: Uint8Array, mediaType: string) => Promise<string>;
101
+ get: (uri: string) => Promise<{
102
+ bytes: Uint8Array;
103
+ mimeType: string;
104
+ } | undefined>;
105
+ };
106
+ /** Checks a schema without accessing storage or checking link targets. */
107
+ static prepareSchema(schema: JsonObject): Promise<PreparedSchema>;
108
+ /** Subscribes after the shared watcher is ready; the returned function unsubscribes. */
109
+ watch(onChange: ChangeListener, options?: WatchOptions): Promise<() => Promise<void>>;
110
+ /** Stops change subscriptions. Future operations on this instance are refused. */
111
+ close(): Promise<void>;
112
+ }