@mak-98/posix-fs-dirvi-app 0.11.0-beta.3 → 0.11.0-beta.4

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,16 +1,16 @@
1
1
  import { z } from 'zod';
2
- import { NavNode, SerializableKey, State, TreeNode, TreeNodeModel, Folds, FoldsModel, Cursor, StateModel } from 'dirvi-lib';
2
+ import type { TreeNode, TreeNodeApi } from 'dirvi-lib';
3
3
  import { UnixPath } from './unix-path.js';
4
4
  /**
5
5
  * A JavaScript-string representation of a non-special POSIX filename.
6
6
  *
7
7
  * Validates invariants needed for a tree entry ID, not full POSIX compatibility.
8
8
  */
9
- export declare const PosixFilenameSchema: z.ZodPipe<z.ZodType<SerializableKey, unknown, z.core.$ZodTypeInternals<SerializableKey, unknown>>, z.ZodString>;
9
+ export declare const posixFilenameSchema: z.ZodString;
10
10
  /**
11
11
  * `Id` type used for posix-fs-dirvi-app.
12
12
  */
13
- export type PosixId = z.output<typeof PosixFilenameSchema>;
13
+ export type PosixId = z.output<typeof posixFilenameSchema>;
14
14
  /**
15
15
  * POSIX-specific meaning attached to a tree node.
16
16
  */
@@ -22,47 +22,9 @@ export type PosixValue = Readonly<{
22
22
  }> | Readonly<{
23
23
  kind: 'directory';
24
24
  }>;
25
- export declare const PosixValueSchema: z.ZodType<PosixValue>;
26
- /**
27
- * An opaque tree whose IDs are POSIX entry names and whose values describe
28
- * POSIX entry semantics.
29
- */
30
25
  export type PosixTreeNode = TreeNode<PosixId, PosixValue>;
31
- export declare const PosixTreeNodeApi: Readonly<{
32
- createLeaf(id: string, value: PosixValue): TreeNode<string, PosixValue>;
33
- createUnloadedBranch(id: string, value: PosixValue): TreeNode<string, PosixValue>;
34
- createLoadedBranch(id: string, value: PosixValue, children: Iterable<TreeNode<string, PosixValue>>): TreeNode<string, PosixValue> | undefined;
35
- id(node: TreeNode<string, PosixValue>): string;
36
- value(node: TreeNode<string, PosixValue>): PosixValue;
37
- kind(node: TreeNode<string, PosixValue>): import("dirvi-lib").TreeNodeKind;
38
- matchByKind<Result>(node: TreeNode<string, PosixValue>, handlers: Readonly<{
39
- leaf: (node: Readonly<{
40
- id: string;
41
- value: PosixValue;
42
- }>) => Result;
43
- unloadedBranch: (node: Readonly<{
44
- id: string;
45
- value: PosixValue;
46
- }>) => Result;
47
- loadedBranch: (node: Readonly<{
48
- id: string;
49
- value: PosixValue;
50
- children: Iterable<TreeNode<string, PosixValue>>;
51
- }>) => Result;
52
- }>): Result;
53
- getLoadedChildren(node: TreeNode<string, PosixValue>): Iterable<TreeNode<string, PosixValue>> | undefined;
54
- findChildById(node: TreeNode<string, PosixValue>, id: string): TreeNode<string, PosixValue> | undefined;
55
- withValue(node: TreeNode<string, PosixValue>, value: PosixValue): TreeNode<string, PosixValue>;
56
- toLeaf(node: TreeNode<string, PosixValue>): TreeNode<string, PosixValue>;
57
- toUnloadedBranch(node: TreeNode<string, PosixValue>): TreeNode<string, PosixValue>;
58
- withLoadedChildren(node: TreeNode<string, PosixValue>, children: Iterable<TreeNode<string, PosixValue>>): TreeNode<string, PosixValue> | undefined;
59
- findAtPath(root: TreeNode<string, PosixValue>, path: readonly string[]): TreeNode<string, PosixValue> | undefined;
60
- selectAtPath<Result>(root: TreeNode<string, PosixValue>, path: readonly string[], selector: (node: TreeNode<string, PosixValue>) => Result): Result | undefined;
61
- updateAtPath(root: TreeNode<string, PosixValue>, path: readonly string[], update: (node: TreeNode<string, PosixValue>) => TreeNode<string, PosixValue> | undefined): TreeNode<string, PosixValue> | undefined;
62
- toModel(node: TreeNode<string, PosixValue>): TreeNodeModel<string, PosixValue>;
63
- fromModel(model: TreeNodeModel<string, PosixValue>): TreeNode<string, PosixValue> | undefined;
64
- }>;
65
- export declare const PosixTreeNode: {
26
+ export declare const posixValueSchema: z.ZodType<PosixValue>;
27
+ export declare function createConstructors(posixTreeNodeApi: TreeNodeApi<PosixId, PosixValue>): {
66
28
  readonly file: (name: PosixId) => PosixTreeNode;
67
29
  readonly symlink: (name: PosixId, target: UnixPath) => PosixTreeNode;
68
30
  readonly unloadedDirectory: (name: PosixId) => PosixTreeNode;
@@ -89,153 +51,4 @@ export declare const PosixTreeNode: {
89
51
  */
90
52
  readonly toUnloadedDirectory: (node: PosixTreeNode) => PosixTreeNode | undefined;
91
53
  };
92
- /**
93
- * This is a DTO / persistence shape, not the runtime domain type.
94
- *
95
- * It intentionally exposes `id`, `value`, and `children`, because serialized
96
- * data must have a concrete public format.
97
- */
98
- export type PosixTreeNodeModel = TreeNodeModel<PosixId, PosixValue>;
99
- /**
100
- * Validates both the generic tree model shape and the POSIX-specific
101
- * file/symlink/directory invariants.
102
- *
103
- * Files and symlinks must be leaf models.
104
- * Directories must be unloaded or loaded branch models.
105
- */
106
- export declare const PosixTreeNodeModelSchema: z.ZodType<PosixTreeNodeModel>;
107
- /**
108
- * Decodes validated external data into the opaque domain type.
109
- *
110
- * `fromModel` additionally checks sibling-name uniqueness. That validation is
111
- * separate from Zod's object-shape validation.
112
- */
113
- export declare function decodePosixTreeNode(input: unknown): PosixTreeNode | undefined;
114
- export declare function encodePosixTreeNode(node: PosixTreeNode): PosixTreeNodeModel;
115
- /**
116
- * Fold definitions for one POSIX directory tree.
117
- */
118
- export type PosixFolds = Folds<PosixId>;
119
- export declare const PosixFoldsApi: Readonly<{
120
- create(rootId: string, initialPrimaryInfo: Readonly<{
121
- name: string;
122
- description: string | null;
123
- }>): Folds<string>;
124
- getIndexByName(folds: Folds<string>, name: string): import("dirvi-lib").FoldIndex | undefined;
125
- getInfoAtIndex(folds: Folds<string>, index: import("dirvi-lib").FoldIndex): Readonly<{
126
- name: string;
127
- description: string | null;
128
- }> | undefined;
129
- isActiveAtIndex(folds: Folds<string>, index: import("dirvi-lib").FoldIndex): boolean | undefined;
130
- hasAtIndex(folds: Folds<string>, index: import("dirvi-lib").FoldIndex): boolean;
131
- indexes(folds: Folds<string>): Iterable<import("dirvi-lib").FoldIndex>;
132
- setAtIndex(folds: Folds<string>, index: import("dirvi-lib").FoldIndex, foldData: Readonly<{
133
- name: string;
134
- description: string | null;
135
- active: boolean;
136
- tree: Readonly<{
137
- id: string;
138
- hiddenEntryIds: readonly string[];
139
- children: readonly Readonly</*elided*/ any>[];
140
- }>;
141
- }>): Folds<string> | undefined;
142
- setAdditionalFoldAtIndex(folds: Folds<string>, index: import("dirvi-lib").FoldIndex, rootId: string, info: Readonly<{
143
- name: string;
144
- description: string | null;
145
- }>): Folds<string> | undefined;
146
- removeAdditionalFoldAtIndex(folds: Folds<string>, index: import("dirvi-lib").FoldIndex): Folds<string> | undefined;
147
- updateInfoAtIndex(folds: Folds<string>, index: import("dirvi-lib").FoldIndex, update: Readonly<{
148
- name?: string;
149
- description?: string | null;
150
- }>): Folds<string> | undefined;
151
- activateAtIndex(folds: Folds<string>, index: import("dirvi-lib").FoldIndex): Folds<string> | undefined;
152
- deactivateAtIndex(folds: Folds<string>, index: import("dirvi-lib").FoldIndex): Folds<string> | undefined;
153
- toggleActiveAtIndex(folds: Folds<string>, index: import("dirvi-lib").FoldIndex): Folds<string> | undefined;
154
- isEntryHiddenInFoldAtPath(folds: Folds<string>, index: import("dirvi-lib").FoldIndex, path: readonly string[], entryId: string): boolean;
155
- isEntryHiddenAtPath(folds: Folds<string>, path: readonly string[], entryId: string): boolean;
156
- hiddenEntryIdsAtPath(folds: Folds<string>, index: import("dirvi-lib").FoldIndex, path: readonly string[]): Iterable<string> | undefined;
157
- hideEntryAtPath(folds: Folds<string>, index: import("dirvi-lib").FoldIndex, path: readonly string[], entryId: string): Folds<string> | undefined;
158
- showEntryAtPath(folds: Folds<string>, index: import("dirvi-lib").FoldIndex, path: readonly string[], entryId: string): Folds<string> | undefined;
159
- showAllHiddenEntriesAtPath(folds: Folds<string>, index: import("dirvi-lib").FoldIndex, path: readonly string[]): Folds<string> | undefined;
160
- toModel(folds: Folds<string>): Readonly<{
161
- slots: readonly [Readonly<{
162
- name: string;
163
- description: string | null;
164
- active: boolean;
165
- tree: Readonly<{
166
- id: string;
167
- hiddenEntryIds: readonly string[];
168
- children: readonly Readonly</*elided*/ any>[];
169
- }>;
170
- }>, ...(Readonly<{
171
- name: string;
172
- description: string | null;
173
- active: boolean;
174
- tree: Readonly<{
175
- id: string;
176
- hiddenEntryIds: readonly string[];
177
- children: readonly Readonly</*elided*/ any>[];
178
- }>;
179
- }> | null)[]];
180
- }>;
181
- fromModel(model: Readonly<{
182
- slots: readonly [Readonly<{
183
- name: string;
184
- description: string | null;
185
- active: boolean;
186
- tree: Readonly<{
187
- id: string;
188
- hiddenEntryIds: readonly string[];
189
- children: readonly Readonly</*elided*/ any>[];
190
- }>;
191
- }>, ...(Readonly<{
192
- name: string;
193
- description: string | null;
194
- active: boolean;
195
- tree: Readonly<{
196
- id: string;
197
- hiddenEntryIds: readonly string[];
198
- children: readonly Readonly</*elided*/ any>[];
199
- }>;
200
- }> | null)[]];
201
- }>): Folds<string> | undefined;
202
- }>;
203
- export type PosixFoldsModel = FoldsModel<PosixId>;
204
- export declare const PosixFoldsModelSchema: z.ZodType<PosixFoldsModel>;
205
- export declare const PosixCursorSchema: z.ZodType<PosixCursor>;
206
- export type PosixCursor = Cursor<PosixId>;
207
- export declare const PosixCursorApi: import("dirvi-lib").CursorApi<string>;
208
- /**
209
- * NavNode should now be parameterized by node value, not the recursive
210
- * application node shape.
211
- */
212
- export type PosixNavNode = NavNode<PosixId>;
213
- export declare const PosixNavApi: import("dirvi-lib").NavNodeApi<string, PosixValue>;
214
- /**
215
- * State should now be parameterized by application value, not a recursive
216
- * structural node type.
217
- */
218
- export type PosixState = State<PosixId, PosixValue>;
219
- export declare const PosixStateApi: Readonly<{
220
- getNodeAtCursor(state: Readonly<{
221
- root: TreeNode<string, PosixValue>;
222
- folds: Folds<string>;
223
- cursor: Cursor<string>;
224
- }>): TreeNode<string, PosixValue> | undefined;
225
- resync(oldState: Readonly<{
226
- root: TreeNode<string, PosixValue>;
227
- folds: Folds<string>;
228
- cursor: Cursor<string>;
229
- }>, loadBranches: (path: readonly string[]) => Promise<readonly TreeNode<string, PosixValue>[]>): Promise<Readonly<{
230
- root: TreeNode<string, PosixValue>;
231
- folds: Folds<string>;
232
- cursor: Cursor<string>;
233
- }>>;
234
- }>;
235
- export type PosixStateModel = StateModel<PosixId, PosixValue>;
236
- /**
237
- * The state schema should operate on a serializable tree *model*, then decode
238
- * it to opaque nodes. Do not try to make Zod construct TreeNode directly.
239
- */
240
- export declare const PosixStateModelSchema: z.ZodType<PosixStateModel>;
241
54
  //# sourceMappingURL=posix-tree.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"posix-tree.d.ts","sourceRoot":"","sources":["../../src/domain/posix-tree.ts"],"names":[],"mappings":"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"}
1
+ {"version":3,"file":"posix-tree.d.ts","sourceRoot":"","sources":["../../src/domain/posix-tree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAEV,QAAQ,EACR,WAAW,EACZ,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,QAAQ,EAAkB,MAAM,gBAAgB,CAAC;AAY1D;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,aAU1B,CAAC;AAEP;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAY3D;;GAEG;AACH,MAAM,MAAM,UAAU,GAClB,QAAQ,CAAC;IACP,IAAI,EAAE,MAAM,CAAC;CACd,CAAC,GACF,QAAQ,CAAC;IACP,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE,QAAQ,CAAC;CAClB,CAAC,GACF,QAAQ,CAAC;IACP,IAAI,EAAE,WAAW,CAAC;CACnB,CAAC,CAAC;AAEP,MAAM,MAAM,aAAa,GAAG,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;AAuB1D,eAAO,MAAM,gBAAgB,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,CAGlD,CAAC;AAMF,wBAAgB,kBAAkB,CAChC,gBAAgB,EAAE,WAAW,CAAC,OAAO,EAAE,UAAU,CAAC;0BAGrC,OAAO,KAAG,aAAa;6BAMpB,OAAO,UAAU,QAAQ,KAAG,aAAa;uCAO/B,OAAO,KAAG,aAAa;qCAOvC,OAAO,YACH,QAAQ,CAAC,aAAa,CAAC,KAChC,aAAa,GAAG,SAAS;IAQ5B;;;;;OAKG;6BACW,aAAa,KAAG,OAAO;IAcrC;;;;;;OAMG;wCAEK,aAAa,YACT,QAAQ,CAAC,aAAa,CAAC,KAChC,aAAa,GAAG,SAAS;IAQ5B;;;;OAIG;yCACuB,aAAa,KAAG,aAAa,GAAG,SAAS;EAQtE"}
@@ -1,16 +1,14 @@
1
1
  import { z } from 'zod';
2
- import { serializableKeySchema, createNavNodeApi, createStateApi, createTreeNodeApi, createFoldsApi, createFoldsModelSchema, createCursorSchema, createCursorApi, createStateModelSchema, } from 'dirvi-lib';
3
2
  import { UnixPathSchema } from './unix-path.js';
4
3
  // -----------------------------------------------------------------------------
5
- // PosixName: Id extends SerializableKey
4
+ // PosixId: Id extends SerializableKey
6
5
  // -----------------------------------------------------------------------------
7
6
  /**
8
7
  * A JavaScript-string representation of a non-special POSIX filename.
9
8
  *
10
9
  * Validates invariants needed for a tree entry ID, not full POSIX compatibility.
11
10
  */
12
- export const PosixFilenameSchema = serializableKeySchema.pipe(z
13
- .string()
11
+ export const posixFilenameSchema = z.string()
14
12
  .min(1, 'Entry name cannot be empty.')
15
13
  .refine((value) => !value.includes('\0'), {
16
14
  message: 'Entry name must not contain a NUL character.',
@@ -20,7 +18,8 @@ export const PosixFilenameSchema = serializableKeySchema.pipe(z
20
18
  })
21
19
  .refine((value) => value !== '.' && value !== '..', {
22
20
  message: "Entry name must not be '.' or '..'.",
23
- }));
21
+ });
22
+ // Schema ----------------------------------------------------------------------
24
23
  const PosixFileEntrySchema = z
25
24
  .object({
26
25
  kind: z.literal('file'),
@@ -37,153 +36,187 @@ const PosixDirectoryEntrySchema = z
37
36
  kind: z.literal('directory'),
38
37
  })
39
38
  .strict();
40
- export const PosixValueSchema = z.discriminatedUnion('kind', [PosixFileEntrySchema, PosixSymlinkEntrySchema, PosixDirectoryEntrySchema]);
41
- export const PosixTreeNodeApi = createTreeNodeApi();
39
+ export const posixValueSchema = z.discriminatedUnion('kind', [PosixFileEntrySchema, PosixSymlinkEntrySchema, PosixDirectoryEntrySchema]);
42
40
  // -----------------------------------------------------------------------------
43
41
  // POSIX domain constructors
44
42
  // -----------------------------------------------------------------------------
45
- export const PosixTreeNode = {
46
- file(name) {
47
- return PosixTreeNodeApi.createLeaf(name, {
48
- kind: 'file',
49
- });
50
- },
51
- symlink(name, target) {
52
- return PosixTreeNodeApi.createLeaf(name, {
53
- kind: 'symlink',
54
- target,
55
- });
56
- },
57
- unloadedDirectory(name) {
58
- return PosixTreeNodeApi.createUnloadedBranch(name, {
59
- kind: 'directory',
60
- });
61
- },
62
- loadedDirectory(name, children) {
63
- return PosixTreeNodeApi.createLoadedBranch(name, { kind: 'directory' }, children);
64
- },
65
- /**
66
- * Runtime domain invariant check.
67
- *
68
- * A file and symlink must be leaves. A directory must be a branch, whether
69
- * loaded or unloaded.
70
- */
71
- isValid(node) {
72
- const entry = PosixTreeNodeApi.value(node);
73
- const treeKind = PosixTreeNodeApi.kind(node);
74
- switch (entry.kind) {
75
- case 'file':
76
- case 'symlink':
77
- return treeKind === 'leaf';
78
- case 'directory':
79
- return treeKind === 'unloaded-branch' || treeKind === 'loaded-branch';
80
- }
81
- },
82
- /**
83
- * Adds or replaces the loaded children of a directory.
84
- *
85
- * Returns `undefined` when:
86
- * - the supplied node is not a directory; or
87
- * - siblings have duplicate names.
88
- */
89
- withLoadedChildren(node, children) {
90
- if (PosixTreeNodeApi.value(node).kind !== 'directory') {
91
- return undefined;
92
- }
93
- return PosixTreeNodeApi.withLoadedChildren(node, children);
94
- },
95
- /**
96
- * Converts a directory to an unloaded directory.
97
- *
98
- * Files and symlinks cannot be converted to branches through this POSIX API.
99
- */
100
- toUnloadedDirectory(node) {
101
- if (PosixTreeNodeApi.value(node).kind !== 'directory') {
102
- return undefined;
103
- }
104
- return PosixTreeNodeApi.toUnloadedBranch(node);
105
- },
106
- };
107
- /**
108
- * Validates both the generic tree model shape and the POSIX-specific
109
- * file/symlink/directory invariants.
110
- *
111
- * Files and symlinks must be leaf models.
112
- * Directories must be unloaded or loaded branch models.
113
- */
114
- export const PosixTreeNodeModelSchema = z.lazy(() => z.union([
115
- // Leaf: file
116
- z
117
- .object({
118
- id: PosixFilenameSchema,
119
- value: PosixFileEntrySchema,
120
- })
121
- .strict(),
122
- // Leaf: symlink
123
- z
124
- .object({
125
- id: PosixFilenameSchema,
126
- value: PosixSymlinkEntrySchema,
127
- })
128
- .strict(),
129
- // Unloaded branch: directory
130
- z
131
- .object({
132
- id: PosixFilenameSchema,
133
- value: PosixDirectoryEntrySchema,
134
- children: z.null(),
135
- })
136
- .strict(),
137
- // Loaded branch: directory
138
- z
139
- .object({
140
- id: PosixFilenameSchema,
141
- value: PosixDirectoryEntrySchema,
142
- children: z.array(PosixTreeNodeModelSchema),
143
- })
144
- .strict(),
145
- ]));
146
- /**
147
- * Decodes validated external data into the opaque domain type.
148
- *
149
- * `fromModel` additionally checks sibling-name uniqueness. That validation is
150
- * separate from Zod's object-shape validation.
151
- */
152
- export function decodePosixTreeNode(input) {
153
- const model = PosixTreeNodeModelSchema.safeParse(input);
154
- if (!model.success) {
155
- return undefined;
156
- }
157
- const node = PosixTreeNodeApi.fromModel(model.data);
158
- if (node === undefined) {
159
- return undefined;
160
- }
161
- return PosixTreeNode.isValid(node) ? node : undefined;
43
+ export function createConstructors(posixTreeNodeApi) {
44
+ return {
45
+ file(name) {
46
+ return posixTreeNodeApi.createLeaf(name, {
47
+ kind: 'file',
48
+ });
49
+ },
50
+ symlink(name, target) {
51
+ return posixTreeNodeApi.createLeaf(name, {
52
+ kind: 'symlink',
53
+ target,
54
+ });
55
+ },
56
+ unloadedDirectory(name) {
57
+ return posixTreeNodeApi.createUnloadedBranch(name, {
58
+ kind: 'directory',
59
+ });
60
+ },
61
+ loadedDirectory(name, children) {
62
+ return posixTreeNodeApi.createLoadedBranch(name, { kind: 'directory' }, children);
63
+ },
64
+ /**
65
+ * Runtime domain invariant check.
66
+ *
67
+ * A file and symlink must be leaves. A directory must be a branch, whether
68
+ * loaded or unloaded.
69
+ */
70
+ isValid(node) {
71
+ const entry = posixTreeNodeApi.value(node);
72
+ const treeKind = posixTreeNodeApi.kind(node);
73
+ switch (entry.kind) {
74
+ case 'file':
75
+ case 'symlink':
76
+ return treeKind === 'leaf';
77
+ case 'directory':
78
+ return treeKind === 'unloaded-branch' || treeKind === 'loaded-branch';
79
+ }
80
+ },
81
+ /**
82
+ * Adds or replaces the loaded children of a directory.
83
+ *
84
+ * Returns `undefined` when:
85
+ * - the supplied node is not a directory; or
86
+ * - siblings have duplicate names.
87
+ */
88
+ withLoadedChildren(node, children) {
89
+ if (posixTreeNodeApi.value(node).kind !== 'directory') {
90
+ return undefined;
91
+ }
92
+ return posixTreeNodeApi.withLoadedChildren(node, children);
93
+ },
94
+ /**
95
+ * Converts a directory to an unloaded directory.
96
+ *
97
+ * Files and symlinks cannot be converted to branches through this POSIX API.
98
+ */
99
+ toUnloadedDirectory(node) {
100
+ if (posixTreeNodeApi.value(node).kind !== 'directory') {
101
+ return undefined;
102
+ }
103
+ return posixTreeNodeApi.toUnloadedBranch(node);
104
+ },
105
+ };
162
106
  }
163
- export function encodePosixTreeNode(node) {
164
- return PosixTreeNodeApi.toModel(node);
165
- }
166
- /**
167
- * Folds internally store sparse trees whose values are direct child IDs hidden
168
- * at that tree position. This implementation detail remains private to the
169
- * POSIX domain module.
170
- */
171
- const PosixFoldTreeNodeApi = createTreeNodeApi();
172
- export const PosixFoldsApi = createFoldsApi(PosixFoldTreeNodeApi);
173
- export const PosixFoldsModelSchema = createFoldsModelSchema(PosixFilenameSchema);
107
+ ;
174
108
  // -----------------------------------------------------------------------------
175
- // PosixCursor
109
+ // Serializable POSIX model
176
110
  // -----------------------------------------------------------------------------
177
- export const PosixCursorSchema = createCursorSchema(PosixFilenameSchema);
178
- export const PosixCursorApi = createCursorApi();
179
- export const PosixNavApi = createNavNodeApi(PosixTreeNodeApi, PosixFoldsApi, PosixCursorApi, {
180
- compareSiblings(left, right) {
181
- return left.id.localeCompare(right.id);
182
- },
183
- });
184
- export const PosixStateApi = createStateApi(PosixTreeNodeApi, PosixCursorApi);
185
- /**
186
- * The state schema should operate on a serializable tree *model*, then decode
187
- * it to opaque nodes. Do not try to make Zod construct TreeNode directly.
188
- */
189
- export const PosixStateModelSchema = createStateModelSchema(PosixTreeNodeModelSchema, PosixFoldsModelSchema, PosixCursorSchema);
111
+ // /**
112
+ // * This is a DTO / persistence shape, not the runtime domain type.
113
+ // *
114
+ // * It intentionally exposes `id`, `value`, and `children`, because serialized
115
+ // * data must have a concrete public format.
116
+ // */
117
+ // export type PosixTreeNodeModel = TreeNodeModel<PosixId, PosixValue>;
118
+ //
119
+ // /**
120
+ // * Validates both the generic tree model shape and the POSIX-specific
121
+ // * file/symlink/directory invariants.
122
+ // *
123
+ // * Files and symlinks must be leaf models.
124
+ // * Directories must be unloaded or loaded branch models.
125
+ // */
126
+ // export const PosixTreeNodeModelSchema: z.ZodType<PosixTreeNodeModel> = z.lazy(
127
+ // () =>
128
+ // z.union([
129
+ // // Leaf: file
130
+ // z
131
+ // .object({
132
+ // id: posixFilenameSchema,
133
+ // value: PosixFileEntrySchema,
134
+ // })
135
+ // .strict(),
136
+ //
137
+ // // Leaf: symlink
138
+ // z
139
+ // .object({
140
+ // id: posixFilenameSchema,
141
+ // value: PosixSymlinkEntrySchema,
142
+ // })
143
+ // .strict(),
144
+ //
145
+ // // Unloaded branch: directory
146
+ // z
147
+ // .object({
148
+ // id: posixFilenameSchema,
149
+ // value: PosixDirectoryEntrySchema,
150
+ // children: z.null(),
151
+ // })
152
+ // .strict(),
153
+ //
154
+ // // Loaded branch: directory
155
+ // z
156
+ // .object({
157
+ // id: posixFilenameSchema,
158
+ // value: PosixDirectoryEntrySchema,
159
+ // children: z.array(PosixTreeNodeModelSchema),
160
+ // })
161
+ // .strict(),
162
+ // ]),
163
+ // );
164
+ // /**
165
+ // * Decodes validated external data into the opaque domain type.
166
+ // *
167
+ // * `fromModel` additionally checks sibling-name uniqueness. That validation is
168
+ // * separate from Zod's object-shape validation.
169
+ // */
170
+ // export function decodePosixTreeNode(input: unknown): PosixTreeNode | undefined {
171
+ // const model = PosixTreeNodeModelSchema.safeParse(input);
172
+ //
173
+ // if (!model.success) {
174
+ // return undefined;
175
+ // }
176
+ //
177
+ // const node = PosixTreeNodeApi.fromModel(model.data);
178
+ //
179
+ // if (node === undefined) {
180
+ // return undefined;
181
+ // }
182
+ //
183
+ // return PosixTreeNode.isValid(node) ? node : undefined;
184
+ // }
185
+ //
186
+ // export function encodePosixTreeNode(node: PosixTreeNode): PosixTreeNodeModel {
187
+ // return PosixTreeNodeApi.toModel(node);
188
+ // }
189
+ // // -----------------------------------------------------------------------------
190
+ // // PosixFolds
191
+ // // -----------------------------------------------------------------------------
192
+ //
193
+ // export type PosixFoldsModel = FoldsModel<PosixId>;
194
+ //
195
+ // export const PosixFoldsModelSchema: z.ZodType<PosixFoldsModel> =
196
+ // createFoldsModelSchema(posixFilenameSchema);
197
+ //
198
+ // // -----------------------------------------------------------------------------
199
+ // // PosixCursor
200
+ // // -----------------------------------------------------------------------------
201
+ //
202
+ // export const PosixCursorSchema: z.ZodType<PosixCursor> =
203
+ // createCursorSchema(posixFilenameSchema);
204
+ //
205
+ // export type PosixCursor = Cursor<PosixId>;
206
+ //
207
+ // // -----------------------------------------------------------------------------
208
+ // // PosixState
209
+ // // -----------------------------------------------------------------------------
210
+ //
211
+ // export type PosixStateModel = StateModel<PosixId, PosixValue>;
212
+ //
213
+ // /**
214
+ // * The state schema should operate on a serializable tree *model*, then decode
215
+ // * it to opaque nodes. Do not try to make Zod construct TreeNode directly.
216
+ // */
217
+ // export const PosixStateModelSchema: z.ZodType<PosixStateModel> =
218
+ // createStateModelSchema(
219
+ // posixTreeNodeModelSchema,
220
+ // PosixFoldsModelSchema,
221
+ // PosixCursorSchema,
222
+ // );
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { posixAppPlugin2 as default } from './posix-fs-dirvi-app.js';
2
- export { posixAppPlugin2 } from './posix-fs-dirvi-app.js';
1
+ export { posixAppPlugin as default } from './posix-fs-dirvi-app.js';
2
+ export { posixAppPlugin } from './posix-fs-dirvi-app.js';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,IAAI,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,IAAI,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC"}
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export { posixAppPlugin2 as default } from './posix-fs-dirvi-app.js';
2
- export { posixAppPlugin2 } from './posix-fs-dirvi-app.js';
1
+ export { posixAppPlugin as default } from './posix-fs-dirvi-app.js';
2
+ export { posixAppPlugin } from './posix-fs-dirvi-app.js';
@@ -1 +1 @@
1
- {"version":3,"file":"create-file-view-api.d.ts","sourceRoot":"","sources":["../../src/infrastructure/create-file-view-api.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,KAAK,EACV,eAAe,EACf,KAAK,EACL,UAAU,EACV,OAAO,EAER,MAAM,WAAW,CAAC;AAEnB;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,CACpB,EAAE,SAAS,eAAe,EAC1B,KAAK,EACL,WAAW,SAAS,UAAU,CAAC,EAAE,EAAE,KAAK,CAAC,IACvC,QAAQ,CAAC;IACX,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAC/B,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,KAAK,WAAW,CAAC;IAOjD,MAAM,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,GAAG,SAAS,CAAC;CAC9D,CAAC,CAAC;AA2BH;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,iBAAiB,CAC/B,EAAE,SAAS,eAAe,EAC1B,KAAK,EACL,WAAW,SAAS,UAAU,CAAC,EAAE,EAAE,KAAK,CAAC,EACzC,GAAG,EACH,EACA,SAAS,EACT,SAAS,EACT,UAAU,GACX,EAAE;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,MAAM,CAAC;IAChC,UAAU,EAAE,UAAU,CAAC,EAAE,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC;CAChD,GAAG,OAAO,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,EAAE,GAAG,CAAC,CAkKjC"}
1
+ {"version":3,"file":"create-file-view-api.d.ts","sourceRoot":"","sources":["../../src/infrastructure/create-file-view-api.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EACV,eAAe,EACf,KAAK,EACL,UAAU,EACV,OAAO,EAER,MAAM,WAAW,CAAC;AAInB;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,CACpB,EAAE,SAAS,eAAe,EAC1B,KAAK,EACL,WAAW,SAAS,UAAU,CAAC,EAAE,EAAE,KAAK,CAAC,IACvC,QAAQ,CAAC;IACX,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAC/B,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,KAAK,WAAW,CAAC;IAOjD,MAAM,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,GAAG,SAAS,CAAC;CAC9D,CAAC,CAAC;AA2BH;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,iBAAiB,CAC/B,EAAE,SAAS,eAAe,EAC1B,KAAK,EACL,WAAW,SAAS,UAAU,CAAC,EAAE,EAAE,KAAK,CAAC,EACzC,GAAG,EACH,EACA,SAAS,EACT,SAAS,EACT,UAAU,GACX,EAAE;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,MAAM,CAAC;IAChC,UAAU,EAAE,UAAU,CAAC,EAAE,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC;CAChD,GAAG,OAAO,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,EAAE,GAAG,CAAC,CAkKjC"}
@@ -1,5 +1,5 @@
1
- import type { TreeNode } from 'dirvi-lib';
1
+ import type { TreeNode, TreeNodeApi } from 'dirvi-lib';
2
2
  import { type PosixValue, type PosixId } from '../domain/posix-tree.js';
3
3
  import { type UnixAbsolutePath } from '../domain/unix-path.js';
4
- export declare function getDirEntries(address: UnixAbsolutePath): Promise<TreeNode<PosixId, PosixValue>[]>;
4
+ export declare function getDirEntries(treeNodeApi: TreeNodeApi<PosixId, PosixValue>, address: UnixAbsolutePath): Promise<TreeNode<PosixId, PosixValue>[]>;
5
5
  //# sourceMappingURL=get-dir-entries.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"get-dir-entries.d.ts","sourceRoot":"","sources":["../../src/infrastructure/get-dir-entries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EACL,KAAK,UAAU,EACf,KAAK,OAAO,EAGb,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,KAAK,gBAAgB,EAAkB,MAAM,wBAAwB,CAAC;AAI/E,wBAAsB,aAAa,CACjC,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC,EAAE,CAAC,CA8B1C"}
1
+ {"version":3,"file":"get-dir-entries.d.ts","sourceRoot":"","sources":["../../src/infrastructure/get-dir-entries.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAEvD,OAAO,EACL,KAAK,UAAU,EACf,KAAK,OAAO,EAIb,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,KAAK,gBAAgB,EAAkB,MAAM,wBAAwB,CAAC;AAE/E,wBAAsB,aAAa,CACjC,WAAW,EAAE,WAAW,CAAC,OAAO,EAAE,UAAU,CAAC,EAC7C,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC,EAAE,CAAC,CA+B1C"}
@@ -1,22 +1,23 @@
1
- import { PosixFilenameSchema, PosixTreeNode, } from '../domain/posix-tree.js';
2
- import { UnixPathSchema } from '../domain/unix-path.js';
3
1
  import { readdir, readlink } from 'node:fs/promises';
4
2
  import { join } from 'node:path';
5
- export async function getDirEntries(address) {
3
+ import { posixFilenameSchema, createConstructors, } from '../domain/posix-tree.js';
4
+ import { UnixPathSchema } from '../domain/unix-path.js';
5
+ export async function getDirEntries(treeNodeApi, address) {
6
6
  const directoryEntries = await readdir(address, {
7
7
  withFileTypes: true,
8
8
  });
9
+ const constructors = createConstructors(treeNodeApi);
9
10
  return Promise.all(directoryEntries.map(async (directoryEntry) => {
10
- const id = PosixFilenameSchema.parse(directoryEntry.name);
11
+ const id = posixFilenameSchema.parse(directoryEntry.name);
11
12
  if (directoryEntry.isSymbolicLink()) {
12
13
  const target = UnixPathSchema.parse(await readlink(join(address, directoryEntry.name)));
13
- return PosixTreeNode.symlink(id, target);
14
+ return constructors.symlink(id, target);
14
15
  }
15
16
  if (directoryEntry.isDirectory()) {
16
- return PosixTreeNode.unloadedDirectory(id);
17
+ return constructors.unloadedDirectory(id);
17
18
  }
18
19
  if (directoryEntry.isFile()) {
19
- return PosixTreeNode.file(id);
20
+ return constructors.file(id);
20
21
  }
21
22
  throw new Error(`Unsupported filesystem entry "${join(address, directoryEntry.name)}"`);
22
23
  }));
@@ -1 +1 @@
1
- {"version":3,"file":"get-unix-abs-path.d.ts","sourceRoot":"","sources":["../../src/infrastructure/get-unix-abs-path.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAEjB,MAAM,wBAAwB,CAAC;AAEhC,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,gBAAgB,CAgBlE"}
1
+ {"version":3,"file":"get-unix-abs-path.d.ts","sourceRoot":"","sources":["../../src/infrastructure/get-unix-abs-path.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,gBAAgB,EAEjB,MAAM,wBAAwB,CAAC;AAEhC,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,gBAAgB,CAgBlE"}
@@ -1,11 +1,2 @@
1
- import { PosixValue, PosixId } from '../domain/posix-tree.js';
2
- import { UnixAbsolutePath } from '../domain/unix-path.js';
3
- import type { AppApi } from 'dirvi-apis';
4
- /**
5
- * Creates the AppApi for the POSIX app.
6
- *
7
- * @param directory - optional directory path for loading the app not at the cwd.
8
- */
9
- export declare function loadNodePosixAppApi(directory?: string): AppApi<PosixId, PosixValue, UnixAbsolutePath>;
10
1
  export declare function createFsResyncSubscription(directory: string): (listener: () => void) => () => void;
11
2
  //# sourceMappingURL=load-node-posix-app-api.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"load-node-posix-app-api.d.ts","sourceRoot":"","sources":["../../src/infrastructure/load-node-posix-app-api.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,UAAU,EAEV,OAAO,EAIR,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAwEzC;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,CAAC,EAAE,MAAM,GACjB,MAAM,CAAC,OAAO,EAAE,UAAU,EAAE,gBAAgB,CAAC,CA0C/C;AAKD,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,MAAM,GAChB,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,MAAM,IAAI,CA6EtC"}
1
+ {"version":3,"file":"load-node-posix-app-api.d.ts","sourceRoot":"","sources":["../../src/infrastructure/load-node-posix-app-api.ts"],"names":[],"mappings":"AAwEA,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,MAAM,GAChB,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,MAAM,IAAI,CA6EtC"}
@@ -1,9 +1,4 @@
1
- import { basename, join } from 'node:path';
2
1
  import { watch } from 'node:fs';
3
- import { getUnixAbsPath } from './get-unix-abs-path.js';
4
- import { getDirEntries } from './get-dir-entries.js';
5
- import { PosixFoldsApi, PosixFilenameSchema, PosixNavApi, PosixTreeNode, } from '../domain/posix-tree.js';
6
- import { createAppStateApis } from 'dirvi-lib';
7
2
  // ---*--- App Data ---*---
8
3
  // Paths for app data:
9
4
  // const environmentPaths = envPaths('dirvi');
@@ -69,46 +64,6 @@ import { createAppStateApis } from 'dirvi-lib';
69
64
  // cursor: PosixCursorApi.getPath(model.cursor),
70
65
  // };
71
66
  // }
72
- // --- Creating Posix App API ---
73
- /**
74
- * Creates the AppApi for the POSIX app.
75
- *
76
- * @param directory - optional directory path for loading the app not at the cwd.
77
- */
78
- export function loadNodePosixAppApi(directory) {
79
- const unixAbsPath = getUnixAbsPath(directory ?? process.cwd());
80
- const rootId = PosixFilenameSchema.parse(basename(unixAbsPath));
81
- const apis = createAppStateApis();
82
- function loadBranches(path) {
83
- const address = join(unixAbsPath, ...path);
84
- return getDirEntries(address);
85
- }
86
- return {
87
- name: unixAbsPath,
88
- rootId,
89
- loadBranches,
90
- createRoot: async () => {
91
- // Start with root branches already loaded
92
- const rootBranches = await loadBranches([]);
93
- const root = PosixTreeNode.loadedDirectory(rootId, rootBranches);
94
- if (root === undefined) {
95
- throw new Error('Cannot create POSIX root: duplicate directory entry names');
96
- }
97
- return root;
98
- },
99
- subscribeToResync: createFsResyncSubscription(join(unixAbsPath)),
100
- // The key for the Posix app instance is just the directory working in:
101
- // viewKey: unixAbsPath,
102
- // viewApi: createFileViewApi({
103
- // directory: posixAppViewsDirectory,
104
- // encodeKey,
105
- // stateCodec: posixStateCodec,
106
- // }),
107
- foldsApi: PosixFoldsApi,
108
- navNodeApi: PosixNavApi,
109
- ...apis,
110
- };
111
- }
112
67
  // `recursive: true` is supported by macOS and Windows, but
113
68
  // recursive watching is not supported on all Node/POSIX
114
69
  // platforms: Linux unsupported.
@@ -1,12 +1,8 @@
1
- import type { AppPlugin, AppPlugin2 } from 'dirvi-apis/plugin';
2
- /**
3
- * A dirvi app that exposes a POSIX filesystem as a navigable tree.
4
- */
5
- export declare const posixAppPlugin: AppPlugin;
1
+ import type { AppPlugin } from 'dirvi-apis';
6
2
  /**
7
3
  * Creates applicator of AppDefinition.
8
4
  *
9
5
  * Input for this app is the absolute path to the directory to open on.
10
6
  */
11
- export declare const posixAppPlugin2: AppPlugin2;
7
+ export declare const posixAppPlugin: AppPlugin;
12
8
  //# sourceMappingURL=posix-fs-dirvi-app.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"posix-fs-dirvi-app.d.ts","sourceRoot":"","sources":["../src/posix-fs-dirvi-app.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,SAAS,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAQ9E;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,SAQ5B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,eAAe,EAAE,UAiD7B,CAAC"}
1
+ {"version":3,"file":"posix-fs-dirvi-app.d.ts","sourceRoot":"","sources":["../src/posix-fs-dirvi-app.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAa5C;;;;GAIG;AACH,eAAO,MAAM,cAAc,EAAE,SAwD5B,CAAC"}
@@ -1,47 +1,36 @@
1
- import { createFsResyncSubscription, loadNodePosixAppApi } from './infrastructure/load-node-posix-app-api.js';
2
- import { PosixFilenameSchema, PosixValueSchema, PosixTreeNode } from './domain/posix-tree.js';
3
1
  import { basename, join } from 'node:path';
2
+ import { posixFilenameSchema, posixValueSchema, createConstructors, } from './domain/posix-tree.js';
3
+ import { createFsResyncSubscription } from './infrastructure/load-node-posix-app-api.js';
4
4
  import { getUnixAbsPath } from './infrastructure/get-unix-abs-path.js';
5
5
  import { getDirEntries } from './infrastructure/get-dir-entries.js';
6
- /**
7
- * A dirvi app that exposes a POSIX filesystem as a navigable tree.
8
- */
9
- export const posixAppPlugin = {
10
- createAppApiApplicator: (input) => {
11
- const appApi = loadNodePosixAppApi(input);
12
- return (appApiConsumer) => {
13
- return appApiConsumer(appApi);
14
- };
15
- },
16
- };
17
6
  /**
18
7
  * Creates applicator of AppDefinition.
19
8
  *
20
9
  * Input for this app is the absolute path to the directory to open on.
21
10
  */
22
- export const posixAppPlugin2 = {
11
+ export const posixAppPlugin = {
23
12
  createAppDefinitionApplicator: (input) => {
24
13
  const unixAbsPath = getUnixAbsPath(input ?? process.cwd());
25
- const rootId = PosixFilenameSchema.parse(basename(unixAbsPath));
26
- function loadDirectoryEntries(path) {
14
+ const rootId = posixFilenameSchema.parse(basename(unixAbsPath));
15
+ function loadDirectoryEntries(treeNodeApi, path) {
27
16
  const address = join(unixAbsPath, ...path);
28
- return getDirEntries(address);
17
+ return getDirEntries(treeNodeApi, address);
29
18
  }
30
19
  const appDefinition = {
31
20
  displayName: `POSIX: ${input}`,
32
21
  rootId,
33
- idSchema: PosixFilenameSchema,
34
- valueSchema: PosixValueSchema,
35
- createRoot: async () => {
22
+ idSchema: posixFilenameSchema,
23
+ valueSchema: posixValueSchema,
24
+ createRoot: async (treeNodeApi) => {
36
25
  // Start with root branches already loaded
37
- const rootBranches = await loadDirectoryEntries([]);
38
- const root = PosixTreeNode.loadedDirectory(rootId, rootBranches);
26
+ const rootBranches = await loadDirectoryEntries(treeNodeApi, []);
27
+ const root = createConstructors(treeNodeApi).loadedDirectory(rootId, rootBranches);
39
28
  if (root === undefined) {
40
29
  throw new Error('Cannot create POSIX root: duplicate directory entry names');
41
30
  }
42
31
  return root;
43
32
  },
44
- loadChildren: loadDirectoryEntries,
33
+ loadChildren: (treeNodeApi, path) => loadDirectoryEntries(treeNodeApi, path),
45
34
  subscribeToResync: createFsResyncSubscription(join(unixAbsPath)),
46
35
  createNavNodeApiOptions: {
47
36
  compareSiblings: (left, right) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mak-98/posix-fs-dirvi-app",
3
- "version": "0.11.0-beta.3",
3
+ "version": "0.11.0-beta.4",
4
4
  "description": "POSIX filesystem app for dirvi.",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "type": "module",
@@ -19,12 +19,12 @@
19
19
  "node": ">=22"
20
20
  },
21
21
  "dependencies": {
22
- "dirvi-apis": "0.11.0-beta.3",
23
- "dirvi-lib": "0.11.0-beta.3",
22
+ "dirvi-apis": "0.11.0-beta.4",
24
23
  "zod": "^4.4.3",
25
24
  "env-paths": "^4.0.0"
26
25
  },
27
26
  "devDependencies": {
27
+ "dirvi-lib": "0.11.0-beta.4",
28
28
  "@types/node": "^22.0.0",
29
29
  "typescript": "^5.0.0"
30
30
  },