Initial commit: notification-elements-demo app

Interactive Angular 19 demo for @sda/notification-elements-ui with
6 sections: Bell & Feed, Notification Center, Inbox, Comments &
Threads, Mention Input, and Full-Featured layout. Includes mock
data, dark mode toggle, and real-time event log.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Giuliano Silvestro
2026-02-13 21:49:19 +10:00
commit 5d0c9ec7eb
36473 changed files with 3778146 additions and 0 deletions

201
node_modules/@jsonjoy.com/fs-node-to-fsa/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2026 Vadims @streamich Daleckis <vadimsdaleckis@gmail.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

30
node_modules/@jsonjoy.com/fs-node-to-fsa/README.md generated vendored Normal file
View File

@@ -0,0 +1,30 @@
# @jsonjoy.com/fs-node-to-fsa
Adapter to convert [Node.js fs API][node-fs] to [File System Access API][fsa] (FSA).
## Installation
```bash
npm install @jsonjoy.com/fs-node-to-fsa
```
## Usage
```ts
import { nodeToFsa } from '@jsonjoy.com/fs-node-to-fsa';
import * as fs from 'fs';
const dir = nodeToFsa(fs, '/path/to/directory', { mode: 'readwrite' });
// Now use the FSA API
for await (const [name, handle] of dir.entries()) {
console.log(name, handle.kind);
}
```
## Reference
- [`nodeToFsa(fs, path, ctx)`](src/index.ts) - Converts a Node.js `fs` module to a `FileSystemDirectoryHandle`.
[node-fs]: https://nodejs.org/api/fs.html
[fsa]: https://developer.mozilla.org/en-US/docs/Web/API/File_System_Access_API

View File

@@ -0,0 +1,72 @@
import { NodeFileSystemHandle } from './NodeFileSystemHandle';
import type { NodeFsaContext, NodeFsaFs } from './types';
import type { GetDirectoryHandleOptions, GetFileHandleOptions, IFileSystemDirectoryHandle, IFileSystemFileHandle, IFileSystemHandle, RemoveEntryOptions } from '@jsonjoy.com/fs-fsa';
/**
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle
*/
export declare class NodeFileSystemDirectoryHandle extends NodeFileSystemHandle implements IFileSystemDirectoryHandle {
protected readonly fs: NodeFsaFs;
protected readonly ctx: NodeFsaContext;
/** Directory path with trailing slash. */
readonly __path: string;
constructor(fs: NodeFsaFs, path: string, ctx?: Partial<NodeFsaContext>);
/**
* Returns a new array iterator containing the keys for each item in
* {@link NodeFileSystemDirectoryHandle} object.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/keys
*/
keys(): AsyncIterableIterator<string>;
/**
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/entries
*/
entries(): AsyncIterableIterator<[string, NodeFileSystemHandle]>;
/**
* Returns a new array iterator containing the values for each index in the
* {@link FileSystemDirectoryHandle} object.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/values
*/
values(): AsyncIterableIterator<NodeFileSystemHandle>;
/**
* Returns a {@link NodeFileSystemDirectoryHandle} for a subdirectory with the specified
* name within the directory handle on which the method is called.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/getDirectoryHandle
* @param name A string representing the {@link NodeFileSystemHandle} name of
* the subdirectory you wish to retrieve.
* @param options An optional object containing options for the retrieved
* subdirectory.
*/
getDirectoryHandle(name: string, options?: GetDirectoryHandleOptions): Promise<IFileSystemDirectoryHandle>;
/**
* Returns a {@link FileSystemFileHandle} for a file with the specified name,
* within the directory the method is called.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/getFileHandle
* @param name A string representing the {@link NodeFileSystemHandle} name of
* the file you wish to retrieve.
* @param options An optional object containing options for the retrieved file.
*/
getFileHandle(name: string, options?: GetFileHandleOptions): Promise<IFileSystemFileHandle>;
/**
* Attempts to remove an entry if the directory handle contains a file or
* directory called the name specified.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/removeEntry
* @param name A string representing the {@link FileSystemHandle} name of the
* entry you wish to remove.
* @param options An optional object containing options.
*/
removeEntry(name: string, { recursive }?: RemoveEntryOptions): Promise<void>;
/**
* The `resolve()` method of the {@link FileSystemDirectoryHandle} interface
* returns an {@link Array} of directory names from the parent handle to the specified
* child entry, with the name of the child entry as the last array item.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/resolve
* @param possibleDescendant The {@link IFileSystemHandle} from which
* to return the relative path.
*/
resolve(possibleDescendant: IFileSystemHandle): Promise<string[] | null>;
}

View File

@@ -0,0 +1,217 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NodeFileSystemDirectoryHandle = void 0;
const NodeFileSystemHandle_1 = require("./NodeFileSystemHandle");
const util_1 = require("./util");
const NodeFileSystemFileHandle_1 = require("./NodeFileSystemFileHandle");
/**
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle
*/
class NodeFileSystemDirectoryHandle extends NodeFileSystemHandle_1.NodeFileSystemHandle {
constructor(fs, path, ctx = {}) {
const fullCtx = (0, util_1.ctx)(ctx);
super('directory', (0, util_1.basename)(path, fullCtx.separator));
this.fs = fs;
this.ctx = fullCtx;
this.__path = path[path.length - 1] === this.ctx.separator ? path : path + this.ctx.separator;
}
/**
* Returns a new array iterator containing the keys for each item in
* {@link NodeFileSystemDirectoryHandle} object.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/keys
*/
async *keys() {
const list = await this.fs.promises.readdir(this.__path);
for (const name of list)
yield '' + name;
}
/**
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/entries
*/
async *entries() {
const { __path: path, fs, ctx } = this;
const list = await fs.promises.readdir(path, { withFileTypes: true });
for (const d of list) {
const dirent = d;
const name = dirent.name + '';
const newPath = path + name;
if (dirent.isDirectory())
yield [name, new NodeFileSystemDirectoryHandle(fs, newPath, ctx)];
else if (dirent.isFile())
yield [name, new NodeFileSystemFileHandle_1.NodeFileSystemFileHandle(fs, newPath, ctx)];
}
}
/**
* Returns a new array iterator containing the values for each index in the
* {@link FileSystemDirectoryHandle} object.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/values
*/
async *values() {
for await (const [, value] of this.entries())
yield value;
}
/**
* Returns a {@link NodeFileSystemDirectoryHandle} for a subdirectory with the specified
* name within the directory handle on which the method is called.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/getDirectoryHandle
* @param name A string representing the {@link NodeFileSystemHandle} name of
* the subdirectory you wish to retrieve.
* @param options An optional object containing options for the retrieved
* subdirectory.
*/
async getDirectoryHandle(name, options) {
(0, util_1.assertName)(name, 'getDirectoryHandle', 'FileSystemDirectoryHandle');
const filename = this.__path + name;
const { fs } = this;
try {
const stats = await fs.promises.stat(filename);
if (!stats.isDirectory())
throw (0, util_1.newTypeMismatchError)();
return new NodeFileSystemDirectoryHandle(fs, filename, this.ctx);
}
catch (error) {
if (error instanceof DOMException)
throw error;
if (error && typeof error === 'object') {
switch (error.code) {
case 'ENOENT': {
if (options?.create) {
(0, util_1.assertCanWrite)(this.ctx.mode);
try {
await fs.promises.mkdir(filename);
}
catch (mkdirError) {
if (mkdirError && typeof mkdirError === 'object' && mkdirError.code === 'EEXIST') {
const stats = await fs.promises.stat(filename);
if (!stats.isDirectory())
throw (0, util_1.newTypeMismatchError)();
return new NodeFileSystemDirectoryHandle(fs, filename, this.ctx);
}
throw mkdirError;
}
return new NodeFileSystemDirectoryHandle(fs, filename, this.ctx);
}
throw (0, util_1.newNotFoundError)();
}
case 'EPERM':
case 'EACCES':
throw (0, util_1.newNotAllowedError)();
}
}
throw error;
}
}
/**
* Returns a {@link FileSystemFileHandle} for a file with the specified name,
* within the directory the method is called.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/getFileHandle
* @param name A string representing the {@link NodeFileSystemHandle} name of
* the file you wish to retrieve.
* @param options An optional object containing options for the retrieved file.
*/
async getFileHandle(name, options) {
(0, util_1.assertName)(name, 'getFileHandle', 'FileSystemDirectoryHandle');
const filename = this.__path + name;
try {
const stats = await this.fs.promises.stat(filename);
if (!stats.isFile())
throw (0, util_1.newTypeMismatchError)();
return new NodeFileSystemFileHandle_1.NodeFileSystemFileHandle(this.fs, filename, this.ctx);
}
catch (error) {
if (error instanceof DOMException)
throw error;
if (error && typeof error === 'object') {
switch (error.code) {
case 'ENOENT': {
if (options?.create) {
(0, util_1.assertCanWrite)(this.ctx.mode);
await this.fs.promises.writeFile(filename, '');
return new NodeFileSystemFileHandle_1.NodeFileSystemFileHandle(this.fs, filename, this.ctx);
}
throw (0, util_1.newNotFoundError)();
}
case 'EPERM':
case 'EACCES':
throw (0, util_1.newNotAllowedError)();
}
}
throw error;
}
}
/**
* Attempts to remove an entry if the directory handle contains a file or
* directory called the name specified.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/removeEntry
* @param name A string representing the {@link FileSystemHandle} name of the
* entry you wish to remove.
* @param options An optional object containing options.
*/
async removeEntry(name, { recursive = false } = {}) {
(0, util_1.assertCanWrite)(this.ctx.mode);
(0, util_1.assertName)(name, 'removeEntry', 'FileSystemDirectoryHandle');
const filename = this.__path + name;
const promises = this.fs.promises;
try {
const stats = await promises.stat(filename);
if (stats.isFile()) {
await promises.unlink(filename);
}
else if (stats.isDirectory()) {
await promises.rmdir(filename, { recursive });
}
else
throw (0, util_1.newTypeMismatchError)();
}
catch (error) {
if (error instanceof DOMException)
throw error;
if (error && typeof error === 'object') {
switch (error.code) {
case 'ENOENT': {
throw (0, util_1.newNotFoundError)();
}
case 'EPERM':
case 'EACCES':
throw (0, util_1.newNotAllowedError)();
case 'ENOTEMPTY':
throw new DOMException('The object can not be modified in this way.', 'InvalidModificationError');
}
}
throw error;
}
}
/**
* The `resolve()` method of the {@link FileSystemDirectoryHandle} interface
* returns an {@link Array} of directory names from the parent handle to the specified
* child entry, with the name of the child entry as the last array item.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/resolve
* @param possibleDescendant The {@link IFileSystemHandle} from which
* to return the relative path.
*/
async resolve(possibleDescendant) {
if (possibleDescendant instanceof NodeFileSystemDirectoryHandle ||
possibleDescendant instanceof NodeFileSystemFileHandle_1.NodeFileSystemFileHandle) {
const path = this.__path;
const childPath = possibleDescendant.__path;
if (!childPath.startsWith(path))
return null;
let relative = childPath.slice(path.length);
if (relative === '')
return [];
const separator = this.ctx.separator;
if (relative[0] === separator)
relative = relative.slice(1);
return relative.split(separator);
}
return null;
}
}
exports.NodeFileSystemDirectoryHandle = NodeFileSystemDirectoryHandle;
//# sourceMappingURL=NodeFileSystemDirectoryHandle.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,28 @@
import { NodeFileSystemHandle } from './NodeFileSystemHandle';
import { NodeFileSystemWritableFileStream } from './NodeFileSystemWritableFileStream';
import type { NodeFsaContext, NodeFsaFs } from './types';
import type { IFileSystemFileHandle, IFileSystemSyncAccessHandle } from '@jsonjoy.com/fs-fsa';
export declare class NodeFileSystemFileHandle extends NodeFileSystemHandle implements IFileSystemFileHandle {
protected readonly fs: NodeFsaFs;
readonly __path: string;
protected readonly ctx: NodeFsaContext;
constructor(fs: NodeFsaFs, __path: string, ctx?: Partial<NodeFsaContext>);
/**
* Returns a {@link Promise} which resolves to a {@link File} object
* representing the state on disk of the entry represented by the handle.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileHandle/getFile
*/
getFile(): Promise<File>;
/**
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileHandle/createSyncAccessHandle
*/
get createSyncAccessHandle(): undefined | (() => Promise<IFileSystemSyncAccessHandle>);
/**
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileHandle/createWritable
*/
createWritable({ keepExistingData }?: CreateWritableOptions): Promise<NodeFileSystemWritableFileStream>;
}
export interface CreateWritableOptions {
keepExistingData?: boolean;
}

View File

@@ -0,0 +1,70 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NodeFileSystemFileHandle = void 0;
const NodeFileSystemHandle_1 = require("./NodeFileSystemHandle");
const NodeFileSystemSyncAccessHandle_1 = require("./NodeFileSystemSyncAccessHandle");
const util_1 = require("./util");
const NodeFileSystemWritableFileStream_1 = require("./NodeFileSystemWritableFileStream");
class NodeFileSystemFileHandle extends NodeFileSystemHandle_1.NodeFileSystemHandle {
constructor(fs, __path, ctx = {}) {
ctx = (0, util_1.ctx)(ctx);
super('file', (0, util_1.basename)(__path, ctx.separator));
this.fs = fs;
this.__path = __path;
this.ctx = ctx;
}
/**
* Returns a {@link Promise} which resolves to a {@link File} object
* representing the state on disk of the entry represented by the handle.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileHandle/getFile
*/
async getFile() {
try {
const path = this.__path;
const promises = this.fs.promises;
const stats = await promises.stat(path);
// TODO: Once implemented, use promises.readAsBlob() instead of promises.readFile().
const data = await promises.readFile(path);
const file = new File([data], this.name, { lastModified: stats.mtime.getTime() });
return file;
}
catch (error) {
if (error instanceof DOMException)
throw error;
if (error && typeof error === 'object') {
switch (error.code) {
case 'EPERM':
case 'EACCES':
throw (0, util_1.newNotAllowedError)();
}
}
throw error;
}
}
/**
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileHandle/createSyncAccessHandle
*/
get createSyncAccessHandle() {
if (!this.ctx.syncHandleAllowed)
return undefined;
return async () => {
if (this.ctx.locks.isLocked(this.__path)) {
throw (0, util_1.newNoModificationAllowedError)();
}
return new NodeFileSystemSyncAccessHandle_1.NodeFileSystemSyncAccessHandle(this.fs, this.__path, this.ctx);
};
}
/**
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileHandle/createWritable
*/
async createWritable({ keepExistingData = false } = { keepExistingData: false }) {
(0, util_1.assertCanWrite)(this.ctx.mode);
if (this.ctx.locks.isLocked(this.__path)) {
throw (0, util_1.newNoModificationAllowedError)();
}
return new NodeFileSystemWritableFileStream_1.NodeFileSystemWritableFileStream(this.fs, this.__path, keepExistingData, this.ctx);
}
}
exports.NodeFileSystemFileHandle = NodeFileSystemFileHandle;
//# sourceMappingURL=NodeFileSystemFileHandle.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"NodeFileSystemFileHandle.js","sourceRoot":"","sources":["../src/NodeFileSystemFileHandle.ts"],"names":[],"mappings":";;;AAAA,iEAA8D;AAC9D,qFAAkF;AAClF,iCAAuH;AACvH,yFAAsF;AAItF,MAAa,wBAAyB,SAAQ,2CAAoB;IAGhE,YACqB,EAAa,EAChB,MAAc,EAC9B,MAA+B,EAAE;QAEjC,GAAG,GAAG,IAAA,UAAS,EAAC,GAAG,CAAC,CAAC;QACrB,KAAK,CAAC,MAAM,EAAE,IAAA,eAAQ,EAAC,MAAM,EAAE,GAAG,CAAC,SAAU,CAAC,CAAC,CAAC;QAL7B,OAAE,GAAF,EAAE,CAAW;QAChB,WAAM,GAAN,MAAM,CAAQ;QAK9B,IAAI,CAAC,GAAG,GAAG,GAAqB,CAAC;IACnC,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,OAAO;QAClB,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC;YACzB,MAAM,QAAQ,GAAG,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC;YAClC,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACxC,oFAAoF;YACpF,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YAC3C,MAAM,IAAI,GAAG,IAAI,IAAI,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6B,GAAE,CAAC;QACxC,CAAC;QACD,OAAO,IAAI,mEAAgC,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,MAAM,EAAE,gBAAgB,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IAChG,CAAC;CACF;AAlED,4DAkEC"}

View File

@@ -0,0 +1,37 @@
import { NodePermissionStatus } from './NodePermissionStatus';
import type { IFileSystemHandle, FileSystemHandlePermissionDescriptor } from '@jsonjoy.com/fs-fsa';
import type { NodeFsaFs, NodeFsaContext } from './types';
/**
* Represents a File System Access API file handle `FileSystemHandle` object,
* which was created from a Node.js `fs` module.
*
* @see [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle)
*/
export declare abstract class NodeFileSystemHandle implements IFileSystemHandle {
readonly kind: 'file' | 'directory';
readonly name: string;
protected abstract readonly fs: NodeFsaFs;
protected abstract readonly __path: string;
protected abstract readonly ctx: NodeFsaContext;
constructor(kind: 'file' | 'directory', name: string);
/**
* Compares two handles to see if the associated entries (either a file or directory) match.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle/isSameEntry
*/
isSameEntry(fileSystemHandle: IFileSystemHandle): boolean;
/**
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle/queryPermission
*/
queryPermission(fileSystemHandlePermissionDescriptor: FileSystemHandlePermissionDescriptor): Promise<NodePermissionStatus>;
/**
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle/remove
*/
remove({ recursive }?: {
recursive?: boolean;
}): Promise<void>;
/**
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle/requestPermission
*/
requestPermission(fileSystemHandlePermissionDescriptor: FileSystemHandlePermissionDescriptor): NodePermissionStatus;
}

View File

@@ -0,0 +1,68 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NodeFileSystemHandle = void 0;
const NodePermissionStatus_1 = require("./NodePermissionStatus");
/**
* Represents a File System Access API file handle `FileSystemHandle` object,
* which was created from a Node.js `fs` module.
*
* @see [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle)
*/
class NodeFileSystemHandle {
constructor(kind, name) {
this.kind = kind;
this.name = name;
}
/**
* Compares two handles to see if the associated entries (either a file or directory) match.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle/isSameEntry
*/
isSameEntry(fileSystemHandle) {
return (this.constructor === fileSystemHandle.constructor && this.__path === fileSystemHandle.__path);
}
/**
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle/queryPermission
*/
async queryPermission(fileSystemHandlePermissionDescriptor) {
const { mode } = fileSystemHandlePermissionDescriptor;
// Check if the requested mode is compatible with the context mode
const requestedMode = mode;
const contextMode = this.ctx.mode;
// If requesting readwrite but context only allows read, deny
if (requestedMode === 'readwrite' && contextMode === 'read') {
return new NodePermissionStatus_1.NodePermissionStatus(requestedMode, 'denied');
}
try {
// Use Node.js fs.promises.access() to check permissions asynchronously
let accessMode = 0 /* AMODE.F_OK */;
if (mode === 'read') {
accessMode = 4 /* AMODE.R_OK */;
}
else if (mode === 'readwrite') {
accessMode = 4 /* AMODE.R_OK */ | 2 /* AMODE.W_OK */;
}
// Use asynchronous access check
await this.fs.promises.access(this.__path, accessMode);
return new NodePermissionStatus_1.NodePermissionStatus(mode, 'granted');
}
catch (error) {
// If access check fails, permission is denied
return new NodePermissionStatus_1.NodePermissionStatus(mode, 'denied');
}
}
/**
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle/remove
*/
async remove({ recursive } = { recursive: false }) {
throw new Error('Not implemented');
}
/**
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle/requestPermission
*/
requestPermission(fileSystemHandlePermissionDescriptor) {
throw new Error('Not implemented');
}
}
exports.NodeFileSystemHandle = NodeFileSystemHandle;
//# sourceMappingURL=NodeFileSystemHandle.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"NodeFileSystemHandle.js","sourceRoot":"","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YAC9C,OAAO,IAAI,2CAAoB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,MAAM,CAAC,EAAE,SAAS,KAA8B,EAAE,SAAS,EAAE,KAAK,EAAE;QAC/E,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IAED;;OAEG;IACI,iBAAiB,CACtB,oCAA0E;QAE1E,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;CACF;AAzED,oDAyEC"}

View File

@@ -0,0 +1,42 @@
import type { FileSystemReadWriteOptions, IFileSystemSyncAccessHandle } from '@jsonjoy.com/fs-fsa';
import type { NodeFsaContext, NodeFsaFs } from './types';
/**
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle
*/
export declare class NodeFileSystemSyncAccessHandle implements IFileSystemSyncAccessHandle {
protected readonly fs: NodeFsaFs;
protected readonly path: string;
protected readonly ctx: NodeFsaContext;
protected readonly fd: number;
constructor(fs: NodeFsaFs, path: string, ctx: NodeFsaContext);
/**
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/close
*/
close(): Promise<void>;
/**
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/flush
*/
flush(): Promise<void>;
/**
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/getSize
*/
getSize(): Promise<number>;
/**
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/read
*/
read(buffer: ArrayBuffer | ArrayBufferView, options?: FileSystemReadWriteOptions): Promise<number>;
/**
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/truncate
* @param newSize The number of bytes to resize the file to.
*/
truncate(newSize: number): Promise<void>;
/**
* Writes the content of a specified buffer to the file associated with the
* handle, optionally at a given offset.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/write
* @param buffer
* @param options
*/
write(buffer: ArrayBuffer | ArrayBufferView | DataView, options?: FileSystemReadWriteOptions): Promise<number>;
}

View File

@@ -0,0 +1,97 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NodeFileSystemSyncAccessHandle = void 0;
const util_1 = require("./util");
const buffer_1 = require("@jsonjoy.com/fs-node-builtins/lib/internal/buffer");
/**
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle
*/
class NodeFileSystemSyncAccessHandle {
constructor(fs, path, ctx) {
this.fs = fs;
this.path = path;
this.ctx = ctx;
this.fd = fs.openSync(path, 'r+');
this.ctx.locks.acquireLock(this.path);
}
/**
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/close
*/
async close() {
(0, util_1.assertCanWrite)(this.ctx.mode);
this.fs.closeSync(this.fd);
this.ctx.locks.releaseLock(this.path);
}
/**
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/flush
*/
async flush() {
(0, util_1.assertCanWrite)(this.ctx.mode);
this.fs.fsyncSync(this.fd);
}
/**
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/getSize
*/
async getSize() {
return this.fs.statSync(this.path).size;
}
/**
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/read
*/
async read(buffer, options = {}) {
const buf = buffer instanceof ArrayBuffer ? buffer_1.Buffer.from(buffer) : buffer;
try {
const size = this.fs.readSync(this.fd, buf, 0, buffer.byteLength, options.at ?? 0);
return size;
}
catch (error) {
if (error instanceof DOMException)
throw error;
if (error && typeof error === 'object') {
switch (error.code) {
case 'EBADF': {
throw new DOMException('File handle already closed.', 'InvalidStateError');
}
}
}
throw error;
}
}
/**
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/truncate
* @param newSize The number of bytes to resize the file to.
*/
async truncate(newSize) {
(0, util_1.assertCanWrite)(this.ctx.mode);
this.fs.truncateSync(this.fd, newSize);
}
/**
* Writes the content of a specified buffer to the file associated with the
* handle, optionally at a given offset.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/write
* @param buffer
* @param options
*/
async write(buffer, options = {}) {
(0, util_1.assertCanWrite)(this.ctx.mode);
const buf = buffer instanceof ArrayBuffer ? buffer_1.Buffer.from(buffer) : buffer;
try {
return this.fs.writeSync(this.fd, buf, 0, buffer.byteLength, options.at ?? 0);
}
catch (error) {
if (error instanceof DOMException)
throw error;
if (error && typeof error === 'object') {
switch (error.code) {
case 'EBADF': {
throw new DOMException('File handle already closed.', 'InvalidStateError');
}
}
}
throw error;
}
}
}
exports.NodeFileSystemSyncAccessHandle = NodeFileSystemSyncAccessHandle;
//# sourceMappingURL=NodeFileSystemSyncAccessHandle.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"NodeFileSystemSyncAccessHandle.js","sourceRoot":"","sources":["../src/NodeFileSystemSyncAccessHandle.ts"],"names":[],"mappings":";;;AAAA,iCAAwC;AACxC,8EAA2E;AAI3E;;GAEG;AACH,MAAa,8BAA8B;IAGzC,YACqB,EAAa,EACb,IAAY,EACZ,GAAmB;QAFnB,OAAE,GAAF,EAAE,CAAW;QACb,SAAI,GAAJ,IAAI,CAAQ;QACZ,QAAG,GAAH,GAAG,CAAgB;QAEtC,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAClC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,KAAK;QAChB,IAAA,qBAAc,EAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC9B,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC3B,IAAI,CAAC,GAA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QAAQ,CAAC,OAAe;QACnC,IAAA,qBAAc,EAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC9B,IAAI,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IACzC,CAAC;IAED;;;;;;;OAOG;IACI,KAAK,CAAC,KAAK,CAChB,MAAgD,EAChD,UAAsC,EAAE;QAExC,IAAA,qBAAc,EAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC9B,MAAM,GAAG,GAA6B,MAAM,YAAY,WAAW,CAAC,CAAC,CAAC,eAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;QACnG,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;QAChF,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,YAAY;gBAAE,MAAM,KAAK,CAAC;YAC/C,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;gBACvC,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;oBACnB,KAAK,OAAO,CAAC,CAAC,CAAC;wBACb,MAAM,IAAI,YAAY,CAAC,6BAA6B,EAAE,mBAAmB,CAAC,CAAC;oBAC7E,CAAC;gBACH,CAAC;YACH,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF;AA9FD,wEA8FC"}

View File

@@ -0,0 +1,56 @@
import type { Data, FileSystemWritableFileStreamParams, IFileSystemWritableFileStream } from '@jsonjoy.com/fs-fsa';
import type { IFileHandle } from '@jsonjoy.com/fs-node-utils/lib/types/misc';
import type { NodeFsaFs, NodeFsaContext } from './types';
/**
* When Chrome writes to the file, it creates a copy of the file with extension
* `.crswap` and then replaces the original file with the copy only when the
* `close()` method is called. If the `abort()` method is called, the `.crswap`
* file is deleted.
*
* If a file name with with extension `.crswap` is already taken, it
* creates a new swap file with extension `.1.crswap` and so on.
*/
export declare const createSwapFile: (fs: NodeFsaFs, path: string, keepExistingData: boolean) => Promise<[handle: IFileHandle, path: string]>;
interface SwapFile {
/** Swap file full path name. */
path: string;
/** Seek offset in the file. */
offset: number;
/** Node.js open FileHandle. */
handle?: IFileHandle;
/** Resolves when swap file is ready for operations. */
ready?: Promise<void>;
}
declare const WS: typeof WritableStream;
/**
* Is a WritableStream object with additional convenience methods, which
* operates on a single file on disk. The interface is accessed through the
* `FileSystemFileHandle.createWritable()` method.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream
*/
export declare class NodeFileSystemWritableFileStream extends WS implements IFileSystemWritableFileStream {
protected readonly fs: NodeFsaFs;
protected readonly path: string;
protected readonly ctx: NodeFsaContext;
protected readonly swap: SwapFile;
constructor(fs: NodeFsaFs, path: string, keepExistingData: boolean, ctx: NodeFsaContext);
/**
* @sse https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream/seek
* @param position An `unsigned long` describing the byte position from the top
* (beginning) of the file.
*/
seek(position: number): Promise<void>;
/**
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream/truncate
* @param size An `unsigned long` of the amount of bytes to resize the stream to.
*/
truncate(size: number): Promise<void>;
protected writeBase(chunk: Data): Promise<void>;
/**
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream/write
*/
write(chunk: Data): Promise<void>;
write(params: FileSystemWritableFileStreamParams): Promise<void>;
}
export {};

View File

@@ -0,0 +1,191 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NodeFileSystemWritableFileStream = exports.createSwapFile = void 0;
const buffer_1 = require("@jsonjoy.com/fs-node-builtins/lib/internal/buffer");
const util_1 = require("./util");
/**
* When Chrome writes to the file, it creates a copy of the file with extension
* `.crswap` and then replaces the original file with the copy only when the
* `close()` method is called. If the `abort()` method is called, the `.crswap`
* file is deleted.
*
* If a file name with with extension `.crswap` is already taken, it
* creates a new swap file with extension `.1.crswap` and so on.
*/
const createSwapFile = async (fs, path, keepExistingData) => {
let handle;
let swapPath = path + '.crswap';
try {
handle = await fs.promises.open(swapPath, 'ax');
}
catch (error) {
if (!error || typeof error !== 'object' || error.code !== 'EEXIST')
throw error;
}
if (!handle) {
for (let i = 1; i < 1000; i++) {
try {
swapPath = `${path}.${i}.crswap`;
handle = await fs.promises.open(swapPath, 'ax');
break;
}
catch (error) {
if (!error || typeof error !== 'object' || error.code !== 'EEXIST')
throw error;
}
}
}
if (!handle)
throw new Error(`Could not create a swap file for "${path}".`);
if (keepExistingData)
await fs.promises.copyFile(path, swapPath, fs.constants.COPYFILE_FICLONE);
return [handle, swapPath];
};
exports.createSwapFile = createSwapFile;
const WS = (typeof WritableStream === 'undefined' ? require('stream/web').WritableStream : WritableStream);
/**
* Is a WritableStream object with additional convenience methods, which
* operates on a single file on disk. The interface is accessed through the
* `FileSystemFileHandle.createWritable()` method.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream
*/
class NodeFileSystemWritableFileStream extends WS {
constructor(fs, path, keepExistingData, ctx) {
const swap = { handle: undefined, path: '', offset: 0 };
super({
async start() {
if (ctx.locks.isLocked(path)) {
throw (0, util_1.newNoModificationAllowedError)();
}
ctx.locks.acquireLock(path);
try {
const promise = (0, exports.createSwapFile)(fs, path, keepExistingData);
swap.ready = promise.then(() => undefined);
const [handle, swapPath] = await promise;
swap.handle = handle;
swap.path = swapPath;
}
catch (error) {
ctx.locks.releaseLock(path);
throw error;
}
},
async write(chunk) {
await swap.ready;
const handle = swap.handle;
if (!handle)
throw new Error('Invalid state');
const buffer = buffer_1.Buffer.from(typeof chunk === 'string'
? chunk
: chunk instanceof Blob
? new Uint8Array(await chunk.arrayBuffer())
: chunk);
const { bytesWritten } = await handle.write(buffer, 0, buffer.length, swap.offset);
swap.offset += bytesWritten;
},
async close() {
await swap.ready;
const handle = swap.handle;
if (!handle)
return;
await handle.close();
await fs.promises.rename(swap.path, path);
ctx.locks.releaseLock(path);
},
async abort() {
await swap.ready;
const handle = swap.handle;
if (!handle)
return;
await handle.close();
await fs.promises.unlink(swap.path);
ctx.locks.releaseLock(path);
},
});
this.fs = fs;
this.path = path;
this.ctx = ctx;
this.swap = swap;
}
/**
* @sse https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream/seek
* @param position An `unsigned long` describing the byte position from the top
* (beginning) of the file.
*/
async seek(position) {
this.swap.offset = position;
}
/**
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream/truncate
* @param size An `unsigned long` of the amount of bytes to resize the stream to.
*/
async truncate(size) {
await this.swap.ready;
const handle = this.swap.handle;
if (!handle)
throw new Error('Invalid state');
await handle.truncate(size);
if (this.swap.offset > size)
this.swap.offset = size;
}
async writeBase(chunk) {
const writer = this.getWriter();
try {
await writer.write(chunk);
}
finally {
writer.releaseLock();
}
}
async write(params) {
if (!params)
throw new TypeError('Missing required argument: params');
switch (typeof params) {
case 'string': {
return this.writeBase(params);
}
case 'object': {
const constructor = params.constructor;
switch (constructor) {
case ArrayBuffer:
case Blob:
case DataView:
return this.writeBase(params);
default: {
if (ArrayBuffer.isView(params)) {
return this.writeBase(params);
}
else {
const options = params;
switch (options.type) {
case 'write': {
if (typeof options.position === 'number')
await this.seek(options.position);
return this.writeBase(params.data);
}
case 'truncate': {
if (typeof params.size !== 'number')
throw new TypeError('Missing required argument: size');
if (this.swap.offset > params.size)
this.swap.offset = params.size;
return this.truncate(params.size);
}
case 'seek':
if (typeof params.position !== 'number')
throw new TypeError('Missing required argument: position');
return this.seek(params.position);
default:
throw new TypeError('Invalid argument: params');
}
}
}
}
}
default:
throw new TypeError('Invalid argument: params');
}
}
}
exports.NodeFileSystemWritableFileStream = NodeFileSystemWritableFileStream;
//# sourceMappingURL=NodeFileSystemWritableFileStream.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,8 @@
/**
* @see [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/PermissionStatus)
*/
export declare class NodePermissionStatus {
readonly name: string;
readonly state: 'granted' | 'denied' | 'prompt';
constructor(name: string, state: 'granted' | 'denied' | 'prompt');
}

View File

@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NodePermissionStatus = void 0;
/**
* @see [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/PermissionStatus)
*/
class NodePermissionStatus {
constructor(name, state) {
this.name = name;
this.state = state;
}
}
exports.NodePermissionStatus = NodePermissionStatus;
//# sourceMappingURL=NodePermissionStatus.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"NodePermissionStatus.js","sourceRoot":"","sources":["../src/NodePermissionStatus.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,MAAa,oBAAoB;IAC/B,YACkB,IAAY,EACZ,KAAsC;QADtC,SAAI,GAAJ,IAAI,CAAQ;QACZ,UAAK,GAAL,KAAK,CAAiC;IACrD,CAAC;CACL;AALD,oDAKC"}

View File

@@ -0,0 +1,7 @@
import { NodeFileSystemDirectoryHandle } from './NodeFileSystemDirectoryHandle';
import { NodeFsaContext, NodeFsaFs } from './types';
export * from './types';
export * from './NodeFileSystemHandle';
export * from './NodeFileSystemDirectoryHandle';
export * from './NodeFileSystemFileHandle';
export declare const nodeToFsa: (fs: NodeFsaFs, dirPath: string, ctx?: Partial<NodeFsaContext>) => NodeFileSystemDirectoryHandle;

14
node_modules/@jsonjoy.com/fs-node-to-fsa/lib/index.js generated vendored Normal file
View File

@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.nodeToFsa = void 0;
const tslib_1 = require("tslib");
const NodeFileSystemDirectoryHandle_1 = require("./NodeFileSystemDirectoryHandle");
tslib_1.__exportStar(require("./types"), exports);
tslib_1.__exportStar(require("./NodeFileSystemHandle"), exports);
tslib_1.__exportStar(require("./NodeFileSystemDirectoryHandle"), exports);
tslib_1.__exportStar(require("./NodeFileSystemFileHandle"), exports);
const nodeToFsa = (fs, dirPath, ctx) => {
return new NodeFileSystemDirectoryHandle_1.NodeFileSystemDirectoryHandle(fs, dirPath, ctx);
};
exports.nodeToFsa = nodeToFsa;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,mFAAgF;AAGhF,kDAAwB;AACxB,iEAAuC;AACvC,0EAAgD;AAChD,qEAA2C;AAEpC,MAAM,SAAS,GAAG,CACvB,EAAa,EACb,OAAe,EACf,GAA6B,EACE,EAAE;IACjC,OAAO,IAAI,6DAA6B,CAAC,EAAE,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;AAC7D,CAAC,CAAC;AANW,QAAA,SAAS,aAMpB"}

View File

@@ -0,0 +1,18 @@
import type { FsPromisesApi, FsSynchronousApi } from '@jsonjoy.com/fs-node-utils';
import type { FsCommonObjects } from '@jsonjoy.com/fs-node-utils/lib/types/FsCommonObjects';
import type { FileLockManager } from '@jsonjoy.com/fs-fsa';
/**
* Required Node.js `fs` module functions for File System Access API.
*/
export type NodeFsaFs = Pick<FsCommonObjects, 'constants'> & {
promises: FsPromisesApi;
} & Pick<FsSynchronousApi, 'openSync' | 'fsyncSync' | 'statSync' | 'closeSync' | 'readSync' | 'truncateSync' | 'writeSync' | 'accessSync'>;
export interface NodeFsaContext {
separator: '/' | '\\';
/** Whether synchronous file handles are allowed. */
syncHandleAllowed: boolean;
/** Whether writes are allowed, defaults to `read`. */
mode: 'read' | 'readwrite';
/** File lock manager for this context. */
locks: FileLockManager;
}

View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=types.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}

12
node_modules/@jsonjoy.com/fs-node-to-fsa/lib/util.d.ts generated vendored Normal file
View File

@@ -0,0 +1,12 @@
import type { NodeFsaContext } from './types';
export { basename } from '@jsonjoy.com/fs-node-utils';
/**
* Creates a new {@link NodeFsaContext}.
*/
export declare const ctx: (partial?: Partial<NodeFsaContext>) => NodeFsaContext;
export declare const assertName: (name: string, method: string, klass: string) => void;
export declare const assertCanWrite: (mode: "read" | "readwrite") => void;
export declare const newNotFoundError: () => DOMException;
export declare const newTypeMismatchError: () => DOMException;
export declare const newNotAllowedError: () => DOMException;
export declare const newNoModificationAllowedError: () => DOMException;

40
node_modules/@jsonjoy.com/fs-node-to-fsa/lib/util.js generated vendored Normal file
View File

@@ -0,0 +1,40 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.newNoModificationAllowedError = exports.newNotAllowedError = exports.newTypeMismatchError = exports.newNotFoundError = exports.assertCanWrite = exports.assertName = exports.ctx = exports.basename = void 0;
const fs_fsa_1 = require("@jsonjoy.com/fs-fsa");
var fs_node_utils_1 = require("@jsonjoy.com/fs-node-utils");
Object.defineProperty(exports, "basename", { enumerable: true, get: function () { return fs_node_utils_1.basename; } });
/**
* Creates a new {@link NodeFsaContext}.
*/
const ctx = (partial = {}) => {
return {
separator: '/',
syncHandleAllowed: false,
mode: 'read',
locks: new fs_fsa_1.FileLockManager(),
...partial,
};
};
exports.ctx = ctx;
const nameRegex = /^(\.{1,2})$|^(.*([\/\\]).*)$/;
const assertName = (name, method, klass) => {
const isInvalid = !name || nameRegex.test(name);
if (isInvalid)
throw new TypeError(`Failed to execute '${method}' on '${klass}': Name is not allowed.`);
};
exports.assertName = assertName;
const assertCanWrite = (mode) => {
if (mode !== 'readwrite')
throw new DOMException('The request is not allowed by the user agent or the platform in the current context.', 'NotAllowedError');
};
exports.assertCanWrite = assertCanWrite;
const newNotFoundError = () => new DOMException('A requested file or directory could not be found at the time an operation was processed.', 'NotFoundError');
exports.newNotFoundError = newNotFoundError;
const newTypeMismatchError = () => new DOMException('The path supplied exists, but was not an entry of requested type.', 'TypeMismatchError');
exports.newTypeMismatchError = newTypeMismatchError;
const newNotAllowedError = () => new DOMException('Permission not granted.', 'NotAllowedError');
exports.newNotAllowedError = newNotAllowedError;
const newNoModificationAllowedError = () => new DOMException('The file is locked and cannot be modified.', 'NoModificationAllowedError');
exports.newNoModificationAllowedError = newNoModificationAllowedError;
//# sourceMappingURL=util.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;;AACA,gDAAsD;AAEtD,4DAAsD;AAA7C,yGAAA,QAAQ,OAAA;AAEjB;;GAEG;AACI,MAAM,GAAG,GAAG,CAAC,UAAmC,EAAE,EAAkB,EAAE;IAC3E,OAAO;QACL,SAAS,EAAE,GAAG;QACd,iBAAiB,EAAE,KAAK;QACxB,IAAI,EAAE,MAAM;QACZ,KAAK,EAAE,IAAI,wBAAe,EAAE;QAC5B,GAAG,OAAO;KACX,CAAC;AACJ,CAAC,CAAC;AARW,QAAA,GAAG,OAQd;AAEF,MAAM,SAAS,GAAG,8BAA8B,CAAC;AAE1C,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,MAAc,EAAE,KAAa,EAAE,EAAE;IACxE,MAAM,SAAS,GAAG,CAAC,IAAI,IAAI,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAChD,IAAI,SAAS;QAAE,MAAM,IAAI,SAAS,CAAC,sBAAsB,MAAM,SAAS,KAAK,yBAAyB,CAAC,CAAC;AAC1G,CAAC,CAAC;AAHW,QAAA,UAAU,cAGrB;AAEK,MAAM,cAAc,GAAG,CAAC,IAA0B,EAAE,EAAE;IAC3D,IAAI,IAAI,KAAK,WAAW;QACtB,MAAM,IAAI,YAAY,CACpB,sFAAsF,EACtF,iBAAiB,CAClB,CAAC;AACN,CAAC,CAAC;AANW,QAAA,cAAc,kBAMzB;AAEK,MAAM,gBAAgB,GAAG,GAAG,EAAE,CACnC,IAAI,YAAY,CACd,0FAA0F,EAC1F,eAAe,CAChB,CAAC;AAJS,QAAA,gBAAgB,oBAIzB;AAEG,MAAM,oBAAoB,GAAG,GAAG,EAAE,CACvC,IAAI,YAAY,CAAC,mEAAmE,EAAE,mBAAmB,CAAC,CAAC;AADhG,QAAA,oBAAoB,wBAC4E;AAEtG,MAAM,kBAAkB,GAAG,GAAG,EAAE,CAAC,IAAI,YAAY,CAAC,yBAAyB,EAAE,iBAAiB,CAAC,CAAC;AAA1F,QAAA,kBAAkB,sBAAwE;AAEhG,MAAM,6BAA6B,GAAG,GAAG,EAAE,CAChD,IAAI,YAAY,CAAC,4CAA4C,EAAE,4BAA4B,CAAC,CAAC;AADlF,QAAA,6BAA6B,iCACqD"}

86
node_modules/@jsonjoy.com/fs-node-to-fsa/package.json generated vendored Normal file
View File

@@ -0,0 +1,86 @@
{
"name": "@jsonjoy.com/fs-node-to-fsa",
"publishConfig": {
"access": "public"
},
"version": "4.56.10",
"description": "Adapter to convert Node.js fs API to File System Access API",
"author": {
"name": "streamich",
"url": "https://github.com/streamich"
},
"homepage": "https://github.com/streamich/memfs/tree/master/packages/fs-node-to-fsa",
"repository": "streamich/memfs",
"license": "Apache-2.0",
"funding": {
"type": "github",
"url": "https://github.com/sponsors/streamich"
},
"keywords": [
"fs",
"filesystem",
"fsa",
"file-system-access",
"node-to-fsa",
"adapter"
],
"engines": {
"node": ">=10.0"
},
"main": "lib/index.js",
"types": "lib/index.d.ts",
"typings": "lib/index.d.ts",
"files": [
"LICENSE",
"lib/"
],
"scripts": {
"clean": "rimraf lib typedocs coverage gh-pages yarn-error.log",
"build": "tsc --project tsconfig.build.json --module commonjs --target es2020 --outDir lib",
"jest": "node -r ts-node/register ./node_modules/.bin/jest",
"test": "jest --maxWorkers 7",
"test:ci": "yarn jest --maxWorkers 3 --no-cache",
"coverage": "yarn test --collectCoverage",
"typedoc": "typedoc",
"typecheck": "tsc -p ."
},
"jest": {
"preset": "ts-jest",
"testEnvironment": "node",
"moduleFileExtensions": [
"ts",
"js",
"tsx"
],
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"transformIgnorePatterns": [
".*/node_modules/.*"
],
"testRegex": ".*/(__tests__|__jest__|demo)/.*\\.(test|spec)\\.tsx?$",
"rootDir": ".",
"testPathIgnorePatterns": [
"node_modules"
]
},
"devDependencies": {
"@jsonjoy.com/fs-node": "4.56.10",
"@types/jest": "^29.0.0",
"@types/node": "^20.0.0",
"jest": "^29.0.0",
"memfs": "4.56.10",
"rimraf": "^5.0.0",
"ts-jest": "^29.4.2",
"ts-node": "^10.9.2",
"typescript": "^5.9.2"
},
"peerDependencies": {
"tslib": "2"
},
"dependencies": {
"@jsonjoy.com/fs-fsa": "4.56.10",
"@jsonjoy.com/fs-node-builtins": "4.56.10",
"@jsonjoy.com/fs-node-utils": "4.56.10"
}
}