@fgv/ts-json-base 5.1.0-2 → 5.1.0-20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.browser.js.map +1 -0
- package/dist/index.js.map +1 -0
- package/dist/packlets/converters/converters.js.map +1 -0
- package/dist/packlets/converters/index.js.map +1 -0
- package/dist/packlets/file-tree/directoryItem.js.map +1 -0
- package/dist/packlets/file-tree/fileItem.js +11 -4
- package/dist/packlets/file-tree/fileItem.js.map +1 -0
- package/dist/packlets/file-tree/fileTree.js.map +1 -0
- package/dist/packlets/file-tree/fileTreeAccessors.js.map +1 -0
- package/dist/packlets/file-tree/fileTreeHelpers.inMemory.js.map +1 -0
- package/dist/packlets/file-tree/fileTreeHelpers.js.map +1 -0
- package/dist/packlets/file-tree/filterSpec.js.map +1 -0
- package/dist/packlets/file-tree/fsTree.js +44 -13
- package/dist/packlets/file-tree/fsTree.js.map +1 -0
- package/dist/packlets/file-tree/in-memory/inMemoryTree.js +44 -13
- package/dist/packlets/file-tree/in-memory/inMemoryTree.js.map +1 -0
- package/dist/packlets/file-tree/in-memory/index.js.map +1 -0
- package/dist/packlets/file-tree/in-memory/treeBuilder.js.map +1 -0
- package/dist/packlets/file-tree/index.browser.js.map +1 -0
- package/dist/packlets/file-tree/index.js.map +1 -0
- package/dist/packlets/json/common.js.map +1 -0
- package/dist/packlets/json/index.js.map +1 -0
- package/dist/packlets/json-compatible/common.js.map +1 -0
- package/dist/packlets/json-compatible/converters.js.map +1 -0
- package/dist/packlets/json-compatible/index.js.map +1 -0
- package/dist/packlets/json-compatible/validators.js.map +1 -0
- package/dist/packlets/json-file/file.js.map +1 -0
- package/dist/packlets/json-file/index.browser.js.map +1 -0
- package/dist/packlets/json-file/index.js.map +1 -0
- package/dist/packlets/json-file/jsonFsHelper.js.map +1 -0
- package/dist/packlets/json-file/jsonLike.js.map +1 -0
- package/dist/packlets/json-file/jsonTreeHelper.js.map +1 -0
- package/dist/packlets/validators/index.js.map +1 -0
- package/dist/packlets/validators/validators.js.map +1 -0
- package/dist/ts-json-base.d.ts +99 -30
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/index.browser.d.ts.map +1 -0
- package/lib/index.browser.js.map +1 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js.map +1 -0
- package/lib/packlets/converters/converters.d.ts.map +1 -0
- package/lib/packlets/converters/converters.js.map +1 -0
- package/lib/packlets/converters/index.d.ts.map +1 -0
- package/lib/packlets/converters/index.js.map +1 -0
- package/lib/packlets/file-tree/directoryItem.d.ts.map +1 -0
- package/lib/packlets/file-tree/directoryItem.js.map +1 -0
- package/lib/packlets/file-tree/fileItem.d.ts +11 -4
- package/lib/packlets/file-tree/fileItem.d.ts.map +1 -0
- package/lib/packlets/file-tree/fileItem.js +11 -4
- package/lib/packlets/file-tree/fileItem.js.map +1 -0
- package/lib/packlets/file-tree/fileTree.d.ts.map +1 -0
- package/lib/packlets/file-tree/fileTree.js.map +1 -0
- package/lib/packlets/file-tree/fileTreeAccessors.d.ts.map +1 -0
- package/lib/packlets/file-tree/fileTreeAccessors.js.map +1 -0
- package/lib/packlets/file-tree/fileTreeHelpers.d.ts.map +1 -0
- package/lib/packlets/file-tree/fileTreeHelpers.inMemory.d.ts.map +1 -0
- package/lib/packlets/file-tree/fileTreeHelpers.inMemory.js.map +1 -0
- package/lib/packlets/file-tree/fileTreeHelpers.js.map +1 -0
- package/lib/packlets/file-tree/filterSpec.d.ts.map +1 -0
- package/lib/packlets/file-tree/filterSpec.js.map +1 -0
- package/lib/packlets/file-tree/fsTree.d.ts +44 -13
- package/lib/packlets/file-tree/fsTree.d.ts.map +1 -0
- package/lib/packlets/file-tree/fsTree.js +44 -13
- package/lib/packlets/file-tree/fsTree.js.map +1 -0
- package/lib/packlets/file-tree/in-memory/inMemoryTree.d.ts +44 -13
- package/lib/packlets/file-tree/in-memory/inMemoryTree.d.ts.map +1 -0
- package/lib/packlets/file-tree/in-memory/inMemoryTree.js +44 -13
- package/lib/packlets/file-tree/in-memory/inMemoryTree.js.map +1 -0
- package/lib/packlets/file-tree/in-memory/index.d.ts.map +1 -0
- package/lib/packlets/file-tree/in-memory/index.js.map +1 -0
- package/lib/packlets/file-tree/in-memory/treeBuilder.d.ts.map +1 -0
- package/lib/packlets/file-tree/in-memory/treeBuilder.js.map +1 -0
- package/lib/packlets/file-tree/index.browser.d.ts.map +1 -0
- package/lib/packlets/file-tree/index.browser.js.map +1 -0
- package/lib/packlets/file-tree/index.d.ts.map +1 -0
- package/lib/packlets/file-tree/index.js.map +1 -0
- package/lib/packlets/json/common.d.ts.map +1 -0
- package/lib/packlets/json/common.js.map +1 -0
- package/lib/packlets/json/index.d.ts.map +1 -0
- package/lib/packlets/json/index.js.map +1 -0
- package/lib/packlets/json-compatible/common.d.ts.map +1 -0
- package/lib/packlets/json-compatible/common.js.map +1 -0
- package/lib/packlets/json-compatible/converters.d.ts.map +1 -0
- package/lib/packlets/json-compatible/converters.js.map +1 -0
- package/lib/packlets/json-compatible/index.d.ts.map +1 -0
- package/lib/packlets/json-compatible/index.js.map +1 -0
- package/lib/packlets/json-compatible/validators.d.ts.map +1 -0
- package/lib/packlets/json-compatible/validators.js.map +1 -0
- package/lib/packlets/json-file/file.d.ts.map +1 -0
- package/lib/packlets/json-file/file.js.map +1 -0
- package/lib/packlets/json-file/index.browser.d.ts.map +1 -0
- package/lib/packlets/json-file/index.browser.js.map +1 -0
- package/lib/packlets/json-file/index.d.ts.map +1 -0
- package/lib/packlets/json-file/index.js.map +1 -0
- package/lib/packlets/json-file/jsonFsHelper.d.ts.map +1 -0
- package/lib/packlets/json-file/jsonFsHelper.js.map +1 -0
- package/lib/packlets/json-file/jsonLike.d.ts.map +1 -0
- package/lib/packlets/json-file/jsonLike.js.map +1 -0
- package/lib/packlets/json-file/jsonTreeHelper.d.ts.map +1 -0
- package/lib/packlets/json-file/jsonTreeHelper.js.map +1 -0
- package/lib/packlets/validators/index.d.ts.map +1 -0
- package/lib/packlets/validators/index.js.map +1 -0
- package/lib/packlets/validators/validators.d.ts.map +1 -0
- package/lib/packlets/validators/validators.js.map +1 -0
- package/package.json +22 -20
- package/dist/test/fixtures/file-tree/config.json +0 -1
- package/dist/test/fixtures/file-tree/data/items.json +0 -1
- package/dist/test/unit/data/file/bad/bad3.json +0 -3
- package/dist/test/unit/data/file/bad/thing1.json +0 -4
- package/dist/test/unit/data/file/bad/thing2.json +0 -3
- package/dist/test/unit/data/file/good/thing1.json +0 -4
- package/dist/test/unit/data/file/good/thing2.json +0 -3
- package/dist/test/unit/json-compatible/helpers.js +0 -32
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"treeBuilder.js","sourceRoot":"","sources":["../../../../src/packlets/file-tree/in-memory/treeBuilder.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,4CAAqE;AAErE;;;GAGG;AACH,MAAa,YAAY;IAevB;;;;;OAKG;IACH,YAAmB,YAAoB,EAAE,QAAiB,EAAE,WAAiB;QAC3E,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;CACF;AA1BD,oCA0BC;AAED;;;GAGG;AACH,MAAa,iBAAiB;IAO5B;;OAEG;IACH,IAAW,QAAQ;QACjB,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;;OAGG;IACH,YAAmB,YAAoB;QACrC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,EAAsD,CAAC;IACjF,CAAC;IAED;;;;;OAKG;IACI,iBAAiB,CAAC,IAAY;QACnC,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC1C,IAAI,QAAQ,EAAE,CAAC;YACb,IAAI,QAAQ,YA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AI,KAAK,EAAE,CAAC;YACzB,MAAM,MAAM,GAAG,GAAG,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;YAC3C,IAAI,MAAM,CAAC,SAAS,EAAE,EAAE,CAAC;gBACvB,OAAO,IAAA,eAAI,EAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC9B,CAAC;YACD,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC;YACnB,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC;gBAC/C,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC;YACjD,CAAC;QACH,CAAC;QACD,OAAO,IAAA,kBAAO,EAAC,GAAG,CAAC,CAAC;IACtB,CAAC;CACF;AAxGD,kCAwGC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Result, captureResult, fail, succeed } from '@fgv/ts-utils';\n\n/**\n * Represents a file in an in-memory file tree.\n * @public\n */\nexport class InMemoryFile<TCT extends string = string> {\n /**\n * The absolute path of the file.\n */\n public readonly absolutePath: string;\n /**\n * The contents of the file.\n */\n public readonly contents: unknown;\n\n /**\n * The content type of the file.\n */\n public readonly contentType?: TCT;\n\n /**\n * Creates a new {@link FileTree.InMemoryFile | InMemoryFile} instance.\n * @param absolutePath - The absolute path of the file.\n * @param contents - The contents of the file.\n * @param contentType - Optional content type of the file.\n */\n public constructor(absolutePath: string, contents: unknown, contentType?: TCT) {\n this.absolutePath = absolutePath;\n this.contents = contents;\n this.contentType = contentType;\n }\n}\n\n/**\n * Represents a directory in an in-memory file tree.\n * @public\n */\nexport class InMemoryDirectory<TCT extends string = string> {\n /**\n * The absolute path of the directory.\n */\n public readonly absolutePath: string;\n protected _children: Map<string, InMemoryDirectory<TCT> | InMemoryFile<TCT>>;\n\n /**\n * The children of the directory.\n */\n public get children(): ReadonlyMap<string, InMemoryDirectory<TCT> | InMemoryFile<TCT>> {\n return this._children;\n }\n\n /**\n * Creates an empty new {@link FileTree.InMemoryDirectory | InMemoryDirectory} instance.\n * @param absolutePath - The absolute path of the directory.\n */\n public constructor(absolutePath: string) {\n this.absolutePath = absolutePath;\n this._children = new Map<string, InMemoryDirectory<TCT> | InMemoryFile<TCT>>();\n }\n\n /**\n * Gets or adds a child directory with the specified name.\n * @param name - The name of the child directory.\n * @returns `Success` with the child directory if successful, or\n * `Failure` with an error message otherwise.\n */\n public getOrAddDirectory(name: string): Result<InMemoryDirectory<TCT>> {\n const existing = this._children.get(name);\n if (existing) {\n if (existing instanceof InMemoryDirectory) {\n return succeed(existing);\n }\n return fail(`${name}: not a directory`);\n }\n const child = new InMemoryDirectory<TCT>(this.getChildPath(name));\n this._children.set(name, child);\n return succeed(child);\n }\n\n /**\n * Adds a file to the directory.\n * @param name - The name of the file.\n * @param contents - The contents of the file.\n * @param contentType - Optional content type of the file.\n * @returns `Success` with the new file if successful, or\n * `Failure` with an error message otherwise.\n */\n public addFile(name: string, contents: unknown, contentType?: TCT): Result<InMemoryFile<TCT>> {\n if (this._children.has(name)) {\n return fail(`${name}: already exists`);\n }\n const child = new InMemoryFile<TCT>(this.getChildPath(name), contents, contentType);\n this._children.set(name, child);\n return succeed(child);\n }\n\n /**\n * Removes a child from the directory.\n * @param name - The name of the child to remove.\n * @returns `true` if the child was found and removed, `false` otherwise.\n */\n public removeChild(name: string): boolean {\n return this._children.delete(name);\n }\n\n /**\n * Gets the absolute path for a child of this directory with the supplied\n * name.\n * @param name - The name of the child.\n * @returns `Success` with the absolute path if successful, or\n * `Failure` with an error message otherwise.\n */\n public getChildPath(name: string): string {\n if (this.absolutePath === '/') {\n return `/${name}`;\n }\n return [this.absolutePath, name].join('/');\n }\n}\n\n/**\n * Helper class to build an in-memory file tree.\n * @public\n */\nexport class TreeBuilder<TCT extends string = string> {\n /**\n * The prefix for all paths in the tree.\n */\n public readonly prefix: string;\n\n /**\n * The root directory of the tree.\n */\n public readonly root: InMemoryDirectory<TCT>;\n\n /**\n * A map of all directories and files in the tree by absolute path.\n */\n public readonly byAbsolutePath: Map<string, InMemoryDirectory<TCT> | InMemoryFile<TCT>>;\n\n /**\n * Protected constructor for derived classes.\n * @param prefix - The prefix for all paths in the tree.\n * @public\n */\n protected constructor(prefix?: string) {\n this.prefix = prefix ?? '/';\n if (!this.prefix.startsWith('/')) {\n throw new Error(`${prefix}: not an absolute path`);\n }\n\n // Normalize the prefix to remove trailing slashes (except for root)\n /* c8 ignore next 3 - tested but code coverage has intermittent issues */\n if (this.prefix !== '/' && this.prefix.endsWith('/')) {\n this.prefix = this.prefix.slice(0, -1);\n }\n\n this.root = new InMemoryDirectory<TCT>(this.prefix);\n this.byAbsolutePath = new Map<string, InMemoryDirectory<TCT> | InMemoryFile<TCT>>();\n this.byAbsolutePath.set(this.prefix, this.root);\n }\n\n /**\n * Creates a new {@link TreeBuilder} instance.\n * @param prefix - The prefix for all paths in the tree.\n * @returns `Success` with the new {@link TreeBuilder} instance if successful,\n * or `Failure` with an error message otherwise.\n * @public\n */\n public static create<TCT extends string = string>(prefix?: string): Result<TreeBuilder<TCT>> {\n return captureResult(() => new TreeBuilder(prefix));\n }\n\n /**\n * Adds a file to the tree.\n * @param absolutePath - The absolute path of the file.\n * @param contents - The contents of the file.\n * @param contentType - The content type of the file.\n * @returns `Success` with the new file if successful, or\n * `Failure` with an error message otherwise.\n * @public\n */\n public addFile(absolutePath: string, contents: unknown, contentType?: TCT): Result<InMemoryFile<TCT>> {\n const parts = absolutePath.split('/').filter((p) => p.length > 0);\n if (parts.length === 0) {\n return fail(`${absolutePath}: invalid file path`);\n }\n let dir = this.root;\n while (parts.length > 1) {\n const part = parts.shift()!;\n const result = dir.getOrAddDirectory(part);\n if (result.isFailure()) {\n return fail(result.message);\n }\n dir = result.value;\n if (!this.byAbsolutePath.has(dir.absolutePath)) {\n this.byAbsolutePath.set(dir.absolutePath, dir);\n }\n }\n return dir.addFile(parts[0], contents, contentType).onSuccess((file: InMemoryFile<TCT>) => {\n this.byAbsolutePath.set(file.absolutePath, file);\n return succeed(file);\n });\n }\n\n /**\n * Ensures a directory exists at the given absolute path, creating\n * intermediate directories as needed.\n * @param absolutePath - The absolute path of the directory.\n * @returns `Success` with the directory if successful, or\n * `Failure` with an error message otherwise.\n * @public\n */\n public addDirectory(absolutePath: string): Result<InMemoryDirectory<TCT>> {\n const parts = absolutePath.split('/').filter((p) => p.length > 0);\n let dir = this.root;\n for (const part of parts) {\n const result = dir.getOrAddDirectory(part);\n if (result.isFailure()) {\n return fail(result.message);\n }\n dir = result.value;\n if (!this.byAbsolutePath.has(dir.absolutePath)) {\n this.byAbsolutePath.set(dir.absolutePath, dir);\n }\n }\n return succeed(dir);\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.browser.d.ts","sourceRoot":"","sources":["../../../src/packlets/file-tree/index.browser.ts"],"names":[],"mappings":"AAyBA,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAG7B,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.browser.js","sourceRoot":"","sources":["../../../src/packlets/file-tree/index.browser.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;AAEH,2EAA2E;AAE3E,qCAAqC;AACrC,sDAAoC;AACpC,6CAA2B;AAC3B,kDAAgC;AAChC,6CAA2B;AAC3B,+CAA6B;AAE7B,yDAAyD;AACzD,8CAA4B;AAC5B,uEAAsD;AAA7C,oHAAA,QAAQ,OAAA;AAEjB,WAAW;AACX,sCAAsC;AACtC,qCAAqC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n// Browser-safe FileTree exports - excludes Node.js filesystem dependencies\n\n// Export core interfaces and classes\nexport * from './fileTreeAccessors';\nexport * from './fileTree';\nexport * from './directoryItem';\nexport * from './fileItem';\nexport * from './filterSpec';\n\n// Export in-memory implementations for web compatibility\nexport * from './in-memory';\nexport { inMemory } from './fileTreeHelpers.inMemory';\n\n// Exclude:\n// - fsTree (requires Node.js fs/path)\n// - fileTreeHelpers (imports fsTree)\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/file-tree/index.ts"],"names":[],"mappings":"AAuBA,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAG7B,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAGtD,cAAc,aAAa,CAAC;AAI5B,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/file-tree/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;AAEH,qCAAqC;AACrC,sDAAoC;AACpC,6CAA2B;AAC3B,kDAAgC;AAChC,6CAA2B;AAC3B,+CAA6B;AAE7B,iFAAiF;AACjF,oDAAkC;AAClC,uEAAsD;AAA7C,oHAAA,QAAQ,OAAA;AAEjB,yDAAyD;AACzD,8CAA4B;AAE5B,uEAAuE;AACvE,4EAA4E;AAC5E,2CAAyB","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n// Export core interfaces and classes\nexport * from './fileTreeAccessors';\nexport * from './fileTree';\nexport * from './directoryItem';\nexport * from './fileItem';\nexport * from './filterSpec';\n\n// Export tree-shakeable helpers (filesystem ones will be shaken out if not used)\nexport * from './fileTreeHelpers';\nexport { inMemory } from './fileTreeHelpers.inMemory';\n\n// Export in-memory implementations for web compatibility\nexport * from './in-memory';\n\n// Note: FsFileTreeAccessors is now only imported by fileTreeHelpers.ts\n// Web apps that don't use forFilesystem() won't bundle fs/path dependencies\nexport * from './fsTree';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/packlets/json/common.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,MAAM,EAAgC,MAAM,eAAe,CAAC;AAErE;;;GAGG;AAEH,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;AAE7D;;;;GAIG;AAEH,MAAM,WAAW,UAAU;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1B;AAED;;;;GAIG;AACH,MAAM,MAAM,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,GAAG,IAAI,YAAY,IAAI,kBAAkB,CAAC,CAAC;YACzD,CAAC;QACH,CAAC;aAAM,CAAC;YACN,OAAO,IAAA,eAAI,EAAC,GAAG,IAAI,YAAY,IAAI,kBAAkB,CAAC,CAAC;QACzD,CAAC;IACH,CAAC;IACD,OAAO,IAAA,kBAAO,EAAC,MAAM,CAAC,CAAC;AACzB,CAAC;AAED;;;;;;;;;GASG;AACH,SAAgB,cAAc,CAAC,GAAe,EAAE,IAAY;IAC1D,OAAO,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE;QAC9C,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;YACrB,OAAO,IAAA,eAAI,EAAC,GAAG,IAAI,iBAAiB,CAAC,CAAC;QACxC,CAAC;QACD,OAAO,IAAA,kBAAO,EAAC,CAAC,CAAC,CAAC;IACpB,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,YAAY,CAAC,IAAa;IACxC,OAAO,IAAA,wBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAC/D,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,kBAAkB,CAAI,IAAO;IAC3C,OAAO,IAAA,wBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAC/D,CAAC","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Result, captureResult, fail, succeed } from '@fgv/ts-utils';\n\n/**\n * Primitive (terminal) values allowed in by JSON.\n * @public\n */\n// eslint-disable-next-line @rushstack/no-new-null\nexport type JsonPrimitive = boolean | number | string | null;\n\n/**\n * A {@link JsonObject | JsonObject} is a string-keyed object\n * containing only valid {@link JsonValue | JSON values}.\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport interface JsonObject {\n [key: string]: JsonValue;\n}\n\n/**\n * A {@link JsonValue | JsonValue} is one of: a {@link JsonPrimitive | JsonPrimitive},\n * a {@link JsonObject | JsonObject} or an {@link JsonArray | JsonArray}.\n * @public\n */\nexport type JsonValue = JsonPrimitive | JsonObject | JsonArray;\n\n/**\n * A {@link JsonArray | JsonArray} is an array containing only valid {@link JsonValue | JsonValues}.\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport interface JsonArray extends Array<JsonValue> {}\n\n/**\n * Classes of {@link JsonValue | JsonValue}.\n * @public\n */\nexport type JsonValueType = 'primitive' | 'object' | 'array';\n\n/**\n * Helper type to detect if T is exactly unknown.\n */\ntype IsUnknown<T> = unknown extends T ? ([T] extends [unknown] ? true : false) : false;\n\n/**\n * A constrained type that is compatible with JSON serialization.\n *\n * This type transforms input types to ensure they can be safely serialized to JSON:\n * - JSON primitives (string, number, boolean, null) are preserved as-is\n * - `undefined` is allowed for TypeScript compatibility with optional properties\n * - Objects are recursively transformed with all properties made JSON-compatible\n * - Arrays are transformed to contain only JSON-compatible elements\n * - Functions are transformed to error types\n * - Other non-JSON types are transformed to error types\n *\n * Note: While `undefined` is technically not JSON-serializable, it's allowed here\n * to support TypeScript's optional property patterns. Use `sanitizeJsonObject`\n * to remove undefined properties before actual JSON serialization.\n *\n * @param T - The type to be constrained\n * @returns A constrained type that is compatible with JSON serialization.\n *\n * @example\n * ```typescript\n * interface IUser {\n * name: string;\n * email?: string; // Optional property can be undefined\n * }\n *\n * type UserCompatible = JsonCompatibleType<IUser>; // Allows undefined for email\n *\n * const user: UserCompatible = {\n * name: \"John\",\n * email: undefined // This works\n * };\n *\n * // Before JSON serialization, sanitize to remove undefined:\n * const sanitized = sanitizeJsonObject(user); // Removes undefined properties\n * JSON.stringify(sanitized.value); // Safe to serialize\n * ```\n *\n * @public\n */\nexport type JsonCompatibleType<T> = IsUnknown<T> extends true\n ? JsonValue\n : T extends JsonPrimitive | undefined\n ? T\n : T extends Array<unknown>\n ? JsonCompatibleArray<T[number]>\n : // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n T extends Function\n ? ['Error: Function is not JSON-compatible']\n : T extends object\n ? { [K in keyof T]: JsonCompatibleType<T[K]> }\n : ['Error: Non-JSON type'];\n\n/**\n * A type that represents an array of JSON-compatible values.\n * @param T - The type to be constrained\n * @returns A constrained type that is compatible with JSON serialization.\n * @public\n */\nexport type JsonCompatibleArray<T> = Array<JsonCompatibleType<T>>;\n\n/**\n * Test if an `unknown` is a {@link JsonValue | JsonValue}.\n * @param from - The `unknown` to be tested\n * @returns `true` if the supplied parameter is a valid {@link JsonPrimitive | JsonPrimitive},\n * `false` otherwise.\n * @public\n */\nexport function isJsonPrimitive(from: unknown): from is JsonPrimitive {\n return typeof from === 'boolean' || typeof from === 'number' || typeof from === 'string' || from === null;\n}\n\n/**\n * Test if an `unknown` is potentially a {@link JsonObject | JsonObject}.\n * @param from - The `unknown` to be tested.\n * @returns `true` if the supplied parameter is a non-array, non-special object\n * with no symbol keys, `false` otherwise.\n * @public\n */\nexport function isJsonObject(from: unknown): from is JsonObject {\n return (\n typeof from === 'object' &&\n from !== null &&\n !Array.isArray(from) &&\n !(from instanceof RegExp) &&\n !(from instanceof Date) &&\n !(from instanceof Map) &&\n !(from instanceof Set) &&\n !(from instanceof Error) &&\n Object.getOwnPropertySymbols(from).length === 0\n );\n}\n\n/**\n * Test if an `unknown` is potentially a {@link JsonArray | JsonArray}.\n * @param from - The `unknown` to be tested.\n * @returns `true` if the supplied parameter is an array object,\n * `false` otherwise.\n * @public\n */\nexport function isJsonArray(from: unknown): from is JsonArray {\n return typeof from === 'object' && Array.isArray(from);\n}\n\n/**\n * Identifies whether some `unknown` value is a {@link JsonPrimitive | primitive},\n * {@link JsonObject | object} or {@link JsonArray | array}. Fails for any value\n * that cannot be converted to JSON (e.g. a function) _but_ this is a shallow test -\n * it does not test the properties of an object or elements in an array.\n * @param from - The `unknown` value to be tested\n * @public\n */\nexport function classifyJsonValue(from: unknown): Result<JsonValueType> {\n if (isJsonPrimitive(from)) {\n return succeed('primitive');\n } else if (isJsonObject(from)) {\n return succeed('object');\n } else if (isJsonArray(from)) {\n return succeed('array');\n }\n return fail(`Invalid JSON: ${from}`);\n}\n\n/**\n * Picks a nested field from a supplied {@link JsonObject | JsonObject}.\n * @param src - The {@link JsonObject | object} from which the field is to be picked.\n * @param path - Dot-separated path of the member to be picked.\n * @returns `Success` with the property if the path is valid, `Failure`\n * with an error message otherwise.\n * @public\n */\nexport function pickJsonValue(src: JsonObject, path: string): Result<JsonValue> {\n let result: JsonValue = src;\n for (const part of path.split('.')) {\n if (result && isJsonObject(result)) {\n result = result[part];\n if (result === undefined) {\n return fail(`${path}: child '${part}' does not exist`);\n }\n } else {\n return fail(`${path}: child '${part}' does not exist`);\n }\n }\n return succeed(result);\n}\n\n/**\n * Picks a nested {@link JsonObject | JsonObject} from a supplied\n * {@link JsonObject | JsonObject}.\n * @param src - The {@link JsonObject | object} from which the field is\n * to be picked.\n * @param path - Dot-separated path of the member to be picked.\n * @returns `Success` with the property if the path is valid and the value\n * is an object. Returns `Failure` with details if an error occurs.\n * @public\n */\nexport function pickJsonObject(src: JsonObject, path: string): Result<JsonObject> {\n return pickJsonValue(src, path).onSuccess((v) => {\n if (!isJsonObject(v)) {\n return fail(`${path}: not an object`);\n }\n return succeed(v);\n });\n}\n\n/**\n * \"Sanitizes\" an `unknown` by stringifying and then parsing it. Guarantees a\n * valid {@link JsonValue | JsonValue} but is not idempotent and gives no guarantees\n * about fidelity. Fails if the supplied value cannot be stringified as Json.\n * @param from - The `unknown` to be sanitized.\n * @returns `Success` with a {@link JsonValue | JsonValue} if conversion succeeds,\n * `Failure` with details if an error occurs.\n * @public\n */\nexport function sanitizeJson(from: unknown): Result<JsonValue> {\n return captureResult(() => JSON.parse(JSON.stringify(from)));\n}\n\n/**\n * Sanitizes some value using JSON stringification and parsing, returning an\n * returning a matching strongly-typed value.\n * @param from - The value to be sanitized.\n * @returns `Success` with a {@link JsonObject | JsonObject} if conversion succeeds,\n * `Failure` with details if an error occurs.\n * @public\n */\nexport function sanitizeJsonObject<T>(from: T): Result<T> {\n return captureResult(() => JSON.parse(JSON.stringify(from)));\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/json/index.ts"],"names":[],"mappings":"AAsBA,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/json/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;AAEH,2CAAyB","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nexport * from './common';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/packlets/json-compatible/common.ts"],"names":[],"mappings":"AAsBA,OAAO,EACL,SAAS,IAAI,aAAa,EAC1B,eAAe,IAAI,mBAAmB,EACtC,UAAU,EACV,SAAS,IAAI,aAAa,EAC3B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE7C;;;GAGG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO,IAAI,aAAa,CAAC,kBAAkB,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAElF;;;GAGG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO,IAAI,aAAa,CAAC,kBAAkB,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAElF;;;GAGG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO,IAAI,mBAAmB,CAAC,kBAAkB,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAE9F;;;GAGG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO,IAAI,UAAU,CAAC,OAAO,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAE7G;;;GAGG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO,IAAI,aAAa,CAAC,kBAAkB,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;AAEzF;;;GAGG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO,IAAI,UAAU,CAAC,OAAO,CAAC,cAAc,CAAC,kBAAkB,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAE3G;;;GAGG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO,EAAE,EAAE,SAAS,MAAM,GAAG,MAAM,IAAI,aAAa,CACtF,MAAM,CAAC,EAAE,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAC,EACjC,EAAE,CACH,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO,EAAE,EAAE,SAAS,MAAM,GAAG,MAAM,IAAI,UAAU,CAAC,SAAS,CAC7F,MAAM,CAAC,EAAE,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAC,EACjC,EAAE,CACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/packlets/json-compatible/common.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport {\n Converter as BaseConverter,\n ObjectConverter as BaseObjectConverter,\n Validation,\n Validator as BaseValidator\n} from '@fgv/ts-utils';\nimport { JsonCompatibleType } from '../json';\n\n/**\n * A converter which converts a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatible} value.\n * @public\n */\nexport type Converter<T, TC = unknown> = BaseConverter<JsonCompatibleType<T>, TC>;\n\n/**\n * A validator which validates a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatible} value.\n * @public\n */\nexport type Validator<T, TC = unknown> = BaseValidator<JsonCompatibleType<T>, TC>;\n\n/**\n * A converter which converts a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatible} value.\n * @public\n */\nexport type ObjectConverter<T, TC = unknown> = BaseObjectConverter<JsonCompatibleType<T>, TC>;\n\n/**\n * A validator which validates a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatible} value.\n * @public\n */\nexport type ObjectValidator<T, TC = unknown> = Validation.Classes.ObjectValidator<JsonCompatibleType<T>, TC>;\n\n/**\n * A converter which converts a supplied `unknown` value to a valid array of {@link JsonCompatibleType | JsonCompatible} values.\n * @public\n */\nexport type ArrayConverter<T, TC = unknown> = BaseConverter<JsonCompatibleType<T>[], TC>;\n\n/**\n * A validator which validates arrays of {@link JsonCompatibleType | JsonCompatible} values in place.\n * @public\n */\nexport type ArrayValidator<T, TC = unknown> = Validation.Classes.ArrayValidator<JsonCompatibleType<T>, TC>;\n\n/**\n * A converter which converts a supplied `unknown` value to a valid record of {@link JsonCompatibleType | JsonCompatible} values.\n * @public\n */\nexport type RecordConverter<T, TC = unknown, TK extends string = string> = BaseConverter<\n Record<TK, JsonCompatibleType<T>>,\n TC\n>;\n\n/**\n * A validator which validates a record of {@link JsonCompatibleType | JsonCompatible} values.\n * @public\n */\nexport type RecordValidator<T, TC = unknown, TK extends string = string> = Validation.Validator<\n Record<TK, JsonCompatibleType<T>>,\n TC\n>;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"converters.d.ts","sourceRoot":"","sources":["../../../src/packlets/json-compatible/converters.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,KAAK,cAAc,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE7C;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO,EACrC,SAAS,EAAE,cAAc,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,cAAc,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,EAC5E,OAAO,GAAE,UAAU,CAAC,OAAuB,GAC1C,cAAc,CAAC,cAAc,CAAC,CAAC,EAAE,EAAE,CAAC,CAEtC;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO,EAAE,EAAE,SAAS,MAAM,GAAG,MA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3,"file":"converters.js","sourceRoot":"","sources":["../../../src/packlets/json-compatible/converters.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;AAcH,0BAKC;AAkBD,4BAKC;AAWD,wBAKC;AAWD,oCAMC;AAWD,kDAKC;AAzFD,4CAAuD;AAIvD;;;;;;;GAOG;AACH,SAAgB,OAAO,CACrB,SAA4E,EAC5E,UAA8B,aAAa;IAE3C,OAAO,qBAAU,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;AAChD,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,QAAQ,CACtB,SAA4E,EAC5E,OAAkD;IAElD,OAAO,qBAAU,CAAC,QAAQ,CAAC,SAAS,EAAE,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;AACxE,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,MAAM,CACpB,UAAiE,EACjE,OAAkE;IAElE,OAAO,IAAI,qBAAU,CAAC,eAAe,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;AAC7D,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,YAAY,CAC1B,UAAiE,EACjE,OAAwE;IAExE,MAAM,aAAa,mCAAQ,OAAO,KAAE,MAAM,EAAE,IAAI,GAAE,CAAC;IACnD,OAAO,IAAI,qBAAU,CAAC,eAAe,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;AACnE,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,mBAAmB,CACjC,iBAAyB,EACzB,UAAmF;IAEnF,OAAO,qBAAU,CAAC,mBAAmB,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC;AACvE,CAAC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Conversion, Converters } from '@fgv/ts-utils';\nimport * as JsonCompatible from './common';\nimport { JsonCompatibleType } from '../json';\n\n/**\n * A helper function to create a {@link JsonCompatible.ArrayConverter | JSON-compatible ArrayConverter<T, TC>}\n * which converts a supplied `unknown` value to a valid array of {@link JsonCompatibleType | JsonCompatibleType<T>}.\n * @param converter - {@link JsonCompatible.Converter | JSON-compatible Converter<T, TC>} or {@link JsonCompatible.Validator | JSON-compatible Validator<T>} used for each item in the source array.\n * @param onError - The error handling option to use for the conversion.\n * @returns A {@link JsonCompatible.ArrayConverter | JSON-compatible ArrayConverter<T, TC>} which returns `JsonCompatibleType<T>[]`.\n * @public\n */\nexport function arrayOf<T, TC = unknown>(\n converter: JsonCompatible.Converter<T, TC> | JsonCompatible.Validator<T, TC>,\n onError: Conversion.OnError = 'failOnError'\n): JsonCompatible.ArrayConverter<T, TC> {\n return Converters.arrayOf(converter, onError);\n}\n\n/**\n * A helper function to create a {@link JsonCompatible.RecordConverter | JSON-compatible RecordConverter<T, TC, TK>}\n * which converts the `string`-keyed properties using a supplied {@link JsonCompatible.Converter | JSON-compatible Converter<T, TC>} or\n * {@link JsonCompatible.Validator | JSON-compatible Validator<T>} to produce a\n * `Record<TK, JsonCompatibleType<T>>`.\n * @remarks\n * If present, the supplied `Converters.KeyedConverterOptions` can provide a strongly-typed\n * converter for keys and/or control the handling of elements that fail conversion.\n * @param converter - {@link JsonCompatible.Converter | JSON-compatible Converter<T, TC>}\n * or {@link JsonCompatible.Validator | JSON-compatible Validator<T>} used for each item in the source object.\n * @param options - Optional `Converters.KeyedConverterOptions<TK, TC>` which\n * supplies a key converter and/or error-handling options.\n * @returns A {@link JsonCompatible.RecordConverter | JSON-compatible RecordConverter<T, TC, TK>} which\n * converts a supplied `unknown` value to a valid record of {@link JsonCompatibleType | JsonCompatible} values.\n * @public\n */\nexport function recordOf<T, TC = unknown, TK extends string = string>(\n converter: JsonCompatible.Converter<T, TC> | JsonCompatible.Validator<T, TC>,\n options?: Converters.KeyedConverterOptions<TK, TC>\n): JsonCompatible.RecordConverter<T, TC, TK> {\n return Converters.recordOf(converter, options ?? { onError: 'fail' });\n}\n\n/**\n * A helper function to create a {@link JsonCompatible.ObjectConverter | JSON-compatible ObjectConverter<T, TC>} which converts a\n * supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.\n * @param properties - The properties to convert.\n * @param options - The options to use for the conversion.\n * @returns A {@link JsonCompatible.ObjectConverter | JSON-compatible ObjectConverter<T, TC>} which\n * converts a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.\n * @public\n */\nexport function object<T, TC = unknown>(\n properties: Conversion.FieldConverters<JsonCompatibleType<T>, TC>,\n options?: Conversion.ObjectConverterOptions<JsonCompatibleType<T>>\n): JsonCompatible.ObjectConverter<T, TC> {\n return new Conversion.ObjectConverter(properties, options);\n}\n\n/**\n * A helper function to create a {@link JsonCompatible.ObjectConverter | JSON-compatible ObjectConverter<T, TC>} which converts a\n * supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.\n * @param properties - The properties to convert.\n * @param options - The options to use for the conversion.\n * @returns A {@link JsonCompatible.ObjectConverter | JSON-compatible ObjectConverter<T, TC>} which\n * converts a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.\n * @public\n */\nexport function strictObject<T, TC = unknown>(\n properties: Conversion.FieldConverters<JsonCompatibleType<T>, TC>,\n options?: Converters.StrictObjectConverterOptions<JsonCompatibleType<T>>\n): JsonCompatible.ObjectConverter<T, TC> {\n const objectOptions = { ...options, strict: true };\n return new Conversion.ObjectConverter(properties, objectOptions);\n}\n\n/**\n * A helper function to create a {@link JsonCompatible.Converter | JSON-compatible Converter<T, TC>} which converts a\n * supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.\n * @param discriminatorProp - The name of the property used to discriminate types.\n * @param converters - The converters to use for the conversion.\n * @returns A {@link JsonCompatible.Converter | JSON-compatible Converter<T, TC>} which\n * converts a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatibleType<T>} value.\n * @public\n */\nexport function discriminatedObject<T, TD extends string = string, TC = unknown>(\n discriminatorProp: string,\n converters: Converters.DiscriminatedObjectConverters<JsonCompatibleType<T>, TD, TC>\n): JsonCompatible.Converter<T, TC> {\n return Converters.discriminatedObject(discriminatorProp, converters);\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/json-compatible/index.ts"],"names":[],"mappings":"AAsBA,cAAc,UAAU,CAAC;AAEzB,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/json-compatible/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,2CAAyB;AAEzB,yDAA2C;AAGlC,gCAAU;AAFnB,yDAA2C;AAEtB,gCAAU","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nexport * from './common';\n\nimport * as Converters from './converters';\nimport * as Validators from './validators';\n\nexport { Converters, Validators };\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../../src/packlets/json-compatible/validators.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,KAAK,cAAc,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEvD;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO,EACrC,eAAe,EAAE,cAAc,CAAC,SAAS,CAAC,CAAC,EAAE,EAA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AM,cAAN,MAAM,GAAI,EAAE,CAAC,CAAC;AAC3D,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,QAAQ,CACtB,eAAgD,EAChD,OAAsD;IAEtD,OAAO,qBAAU,CAAC,QAAQ,CAAC,eAAe,EAAE,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,CAAC,CAAC;AAC7D,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,MAAM,CACpB,UAAyE,EACzE,MAAuG;IAEvG,OAAO,qBAAU,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC,CAAC;AACrD,CAAC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { JsonCompatibleType } from '../json';\nimport * as JsonCompatible from './common';\nimport { Validation, Validators } from '@fgv/ts-utils';\n\n/**\n * A helper function to create a {@link JsonCompatible.ArrayValidator | JSON-compatible ArrayValidator<T, TC>} which validates a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatible} value.\n * @param validateElement - The element validator to use.\n * @param params - The parameters to use for the validation.\n * @returns A {@link JsonCompatible.ArrayValidator | JSON-compatible ArrayValidator<T, TC>} which validates a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatible} value.\n * @public\n */\nexport function arrayOf<T, TC = unknown>(\n validateElement: JsonCompatible.Validator<T, TC>,\n params?: Omit<\n Validation.Classes.ArrayValidatorConstructorParams<JsonCompatibleType<T>, TC>,\n 'validateElement'\n >\n): JsonCompatible.ArrayValidator<T, TC> {\n return Validators.arrayOf(validateElement, params ?? {});\n}\n\n/**\n * A helper function to create a {@link JsonCompatible.RecordValidator | JSON-compatible RecordValidator<T, TC, TK>} which validates a supplied `unknown` value\n * to a valid {@link JsonCompatibleType | JsonCompatible} value.\n * @param validateElement - The element validator to use.\n * @param options - The options to use for the validation.\n * @returns A `Validation.Validator<Record<TK, JsonCompatibleType<T>>, TC>` which validates a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatible} value.\n * @public\n */\nexport function recordOf<T, TC = unknown, TK extends string = string>(\n validateElement: JsonCompatible.Validator<T, TC>,\n options?: Validators.IRecordOfValidatorOptions<TK, TC>\n): JsonCompatible.RecordValidator<T, TC, TK> {\n return Validators.recordOf(validateElement, options ?? {});\n}\n\n/**\n * A helper function to create a {@link JsonCompatible.ObjectValidator | JSON-compatible ObjectValidator<T, TC>} which validates a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatible} value.\n * @param properties - The properties to validate.\n * @param params - The parameters to use for the validation.\n * @returns A {@link JsonCompatible.ObjectValidator | JSON-compatible ObjectValidator<T, TC>} which validates a supplied `unknown` value to a valid {@link JsonCompatibleType | JsonCompatible} value.\n * @public\n */\nexport function object<T, TC = unknown>(\n properties: Validation.Classes.FieldValidators<JsonCompatibleType<T>, TC>,\n params?: Omit<Validation.Classes.ObjectValidatorConstructorParams<JsonCompatibleType<T>, TC>, 'fields'>\n): JsonCompatible.ObjectValidator<T, TC> {\n return Validators.object(properties, params ?? {});\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../../src/packlets/json-file/file.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAEL,uBAAuB,EACvB,4BAA4B,EAC5B,kBAAkB,EAEnB,MAAM,gBAAgB,CAAC;AAGxB;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,CAEnE;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO,EACjD,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,GAC1B,MAAM,CAAC,CAAC,CAAC,CAEX;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO,EACtD,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,uBAAuB,CAAC,CAAC,EAAE,EAAE,CAAC,GACtC,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC,EAAE,CAAC,CAEjC;AAED;;;;;;;;GAQG;AACH,wBAAgB,6BAA6B,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO,EAC3D,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,4BAA4B,CAAC,CAAC,EAAE,EAAE,CAAC,GAC3C,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAExB;AAOD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,CAEpF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.js","sourceRoot":"","sources":["../../../src/packlets/json-file/file.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;AAiBH,4CAEC;AASD,kDAKC;AASD,4DAKC;AAWD,sEAKC;AAWD,8CAEC;AAxED,iDAMwB;AACxB,yCAA6C;AAE7C;;;GAGG;AACH,SAAgB,gBAAgB,CAAC,OAAe;IAC9C,OAAO,kCAAmB,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;AACvD,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,mBAAmB,CACjC,OAAe,EACf,SAA2B;IAE3B,OAAO,kCAAmB,CAAC,mBAAmB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;AACrE,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,wBAAwB,CACtC,OAAe,EACf,OAAuC;IAEvC,OAAO,kCAAmB,CAAC,wBAAwB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AACxE,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,6BAA6B,CAC3C,OAAe,EACf,OAA4C;IAE5C,OAAO,kCAAmB,CAAC,6BAA6B,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAC7E,CAAC;AAED,MAAM,kBAAkB,GAAiB,IAAI,2BAAY,CAAC;IACxD,IAAI,EAAE,0BAAe;IACrB,mBAAmB,EAAE,IAAI,CAAC,oBAAoB;CAC/C,CAAC,CAAC;AAEH;;;GAGG;AACH,SAAgB,iBAAiB,CAAC,OAAe,EAAE,KAAgB;IACjE,OAAO,kBAAkB,CAAC,iBAAiB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AAC9D,CAAC","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Converter, Result } from '@fgv/ts-utils';\nimport { JsonValue } from '../json';\nimport {\n DefaultJsonFsHelper,\n IJsonFsDirectoryOptions,\n IJsonFsDirectoryToMapOptions,\n IReadDirectoryItem,\n JsonFsHelper\n} from './jsonFsHelper';\nimport { DefaultJsonLike } from './jsonLike';\n\n/**\n * {@inheritDoc JsonFile.JsonFsHelper.readJsonFileSync}\n * @public\n */\nexport function readJsonFileSync(srcPath: string): Result<JsonValue> {\n return DefaultJsonFsHelper.readJsonFileSync(srcPath);\n}\n\n/**\n * Read a JSON file and apply a supplied converter.\n * @param srcPath - Path of the file to read.\n * @param converter - `Converter` used to convert the file contents\n * @returns `Success` with a result of type `<T>`, or `Failure`* with a message if an error occurs.\n * @public\n */\nexport function convertJsonFileSync<T, TC = unknown>(\n srcPath: string,\n converter: Converter<T, TC>\n): Result<T> {\n return DefaultJsonFsHelper.convertJsonFileSync(srcPath, converter);\n}\n\n/**\n * Reads all JSON files from a directory and apply a supplied converter.\n * @param srcPath - The path of the folder to be read.\n * @param options - {@link JsonFile.IJsonFsDirectoryOptions | Options} to control\n * conversion and filtering\n * @public\n */\nexport function convertJsonDirectorySync<T, TC = unknown>(\n srcPath: string,\n options: IJsonFsDirectoryOptions<T, TC>\n): Result<IReadDirectoryItem<T>[]> {\n return DefaultJsonFsHelper.convertJsonDirectorySync(srcPath, options);\n}\n\n/**\n * Reads and converts all JSON files from a directory, returning a\n * `Map<string, T>` indexed by file base name (i.e. minus the extension)\n * with an optional name transformation applied if present.\n * @param srcPath - The path of the folder to be read.\n * @param options - {@link JsonFile.IJsonFsDirectoryToMapOptions | Options} to control conversion,\n * filtering and naming.\n * @public\n */\nexport function convertJsonDirectoryToMapSync<T, TC = unknown>(\n srcPath: string,\n options: IJsonFsDirectoryToMapOptions<T, TC>\n): Result<Map<string, T>> {\n return DefaultJsonFsHelper.convertJsonDirectoryToMapSync(srcPath, options);\n}\n\nconst CompatJsonFsHelper: JsonFsHelper = new JsonFsHelper({\n json: DefaultJsonLike,\n allowUndefinedWrite: true // for compatibility\n});\n\n/**\n * {@inheritDoc JsonFile.JsonFsHelper.writeJsonFileSync}\n * @public\n */\nexport function writeJsonFileSync(srcPath: string, value: JsonValue): Result<boolean> {\n return CompatJsonFsHelper.writeJsonFileSync(srcPath, value);\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.browser.d.ts","sourceRoot":"","sources":["../../../src/packlets/json-file/index.browser.ts"],"names":[],"mappings":"AAyBA,cAAc,YAAY,CAAC;AAG3B,cAAc,kBAAkB,CAAC;AAIjC,YAAY,EACV,uBAAuB,EACvB,kBAAkB,EAClB,yBAAyB,EACzB,4BAA4B,EAC5B,mBAAmB,EACnB,uBAAuB,EACxB,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.browser.js","sourceRoot":"","sources":["../../../src/packlets/json-file/index.browser.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;AAEH,4EAA4E;AAE5E,yCAAyC;AACzC,6CAA2B;AAE3B,gDAAgD;AAChD,mDAAiC;AAajC,WAAW;AACX,4DAA4D;AAC5D,4CAA4C","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n// Browser-safe JSON file exports - excludes Node.js filesystem dependencies\n\n// Export browser-safe core functionality\nexport * from './jsonLike';\n\n// Export FileTree-based helper (web-compatible)\nexport * from './jsonTreeHelper';\n\n// Export type definitions only (for TypeScript compatibility)\n// Re-export types from jsonFsHelper without importing the implementation\nexport type {\n IJsonFsDirectoryOptions,\n IReadDirectoryItem,\n ItemNameTransformFunction,\n IJsonFsDirectoryToMapOptions,\n IJsonFsHelperConfig,\n JsonFsHelperInitOptions\n} from './jsonFsHelper';\n\n// Exclude:\n// - file.ts (wraps jsonFsHelper - requires Node.js fs/path)\n// - jsonFsHelper (requires Node.js fs/path)\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/json-file/index.ts"],"names":[],"mappings":"AAuBA,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAG3B,cAAc,kBAAkB,CAAC;AAIjC,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/json-file/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;AAEH,sDAAsD;AACtD,yCAAuB;AACvB,6CAA2B;AAE3B,gDAAgD;AAChD,mDAAiC;AAEjC,wDAAwD;AACxD,+DAA+D;AAC/D,iDAA+B","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n// Export core JSON functionality (no filesystem deps)\nexport * from './file';\nexport * from './jsonLike';\n\n// Export FileTree-based helper (web-compatible)\nexport * from './jsonTreeHelper';\n\n// Export filesystem helpers separately for tree-shaking\n// Web apps that don't import JsonFsHelper won't bundle fs/path\nexport * from './json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gB;QACxD,OAAO,IAAA,wBAAa,EAAC,GAAG,EAAE;YACxB,MAAM,QAAQ,GAAG,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YACvC,MAAM,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;YACpE,sBAAsB;YACtB,IAAI,WAAW,KAAK,SAAS,IAAI,IAAI,CAAC,MAAM,CAAC,mBAAmB,KAAK,IAAI,EAAE,CAAC;gBAC1E,MAAM,IAAI,KAAK,CAAC,uBAAuB,KAAK,EAAE,CAAC,CAAC;YAClD,CAAC;YACD,YAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,WAAY,CAAC,CAAC;YACzC,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC;IAES,mBAAmB,CAAQ,OAAuC,EAAE,IAAY;;QACxF,sBAAsB;QACtB,MAAM,KAAK,GAAG,MAAA,OAAO,CAAC,KAAK,mCAAI,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC;QACxD,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACzC,CAAC;CACF;AA3ID,oCA2IC;AAED;;GAEG;AACU,QAAA,mBAAmB,GAAiB,IAAI,YAAY,EAAE,CAAC","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Converter, Result, Validator, captureResult, fail, mapResults, succeed } from '@fgv/ts-utils';\nimport fs from 'fs';\nimport path from 'path';\n\nimport { JsonValue } from '../json';\nimport { DefaultJsonLike, IJsonLike } from './jsonLike';\n\n/**\n * Options for directory conversion.\n * TODO: add filtering, allowed and excluded.\n * @public\n */\nexport interface IJsonFsDirectoryOptions<T, TC = unknown> {\n /**\n * The converter used to convert incoming JSON objects.\n */\n converter: Converter<T, TC> | Validator<T, TC>;\n\n /**\n * Filter applied to items in the directory\n */\n files?: RegExp[];\n}\n\n/**\n * Return value for one item in a directory conversion.\n * @public\n */\nexport interface IReadDirectoryItem<T> {\n /**\n * Relative name of the file that was processed\n */\n filename: string;\n\n /**\n * The payload of the file.\n */\n item: T;\n}\n\n/**\n * Function to transform the name of a some entity, given an original name\n * and the contents of the entity.\n * @public\n */\nexport type ItemNameTransformFunction<T> = (name: string, item: T) => Result<string>;\n\n/**\n * Options controlling conversion of a directory to a `Map`.\n * @public\n */\nexport interface IJsonFsDirectoryToMapOptions<T, TC = unknown> extends IJsonFsDirectoryOptions<T, TC> {\n transformName?: ItemNameTransformFunction<T>;\n}\n\n/**\n * Function to transform the name of some entity, given only a previous name. This\n * default implementation always returns `Success` with the value that was passed in.\n * @param n - The name to be transformed.\n * @returns - `Success` with the string that was passed in.\n * @public\n */\nconst defaultNameTransformer = (n: string): Result<string> => succeed(n);\n\n/**\n * Configuration for {@link JsonFile.JsonFsHelper | JsonFsHelper}.\n * @public\n */\nexport interface IJsonFsHelperConfig {\n json: IJsonLike;\n allowUndefinedWrite: boolean;\n defaultFiles: RegExp[];\n}\n\n/**\n * Initialization options for {@link JsonFile.JsonFsHelper | JsonFsHelper}.\n * @public\n */\nexport type JsonFsHelperInitOptions = Partial<IJsonFsHelperConfig>;\n\n/**\n * Default configuration for {@link JsonFile.JsonFsHelper | JsonFsHelper}.\n * @public\n */\nexport const DefaultJsonFsHelperConfig: IJsonFsHelperConfig = {\n json: DefaultJsonLike,\n allowUndefinedWrite: false,\n defaultFiles: [/.*.json/]\n};\n\n/**\n * Helper class to simplify common filesystem operations involving JSON (or JSON-like)\n * files.\n * @public\n */\nexport class JsonFsHelper {\n /**\n * Configuration for this {@link JsonFile.JsonFsHelper | JsonFsHelper}.\n */\n public readonly config: IJsonFsHelperConfig;\n\n /**\n * Construct a new {@link JsonFile.JsonFsHelper | JsonFsHelper}.\n * @param init - Optional {@link JsonFile.JsonFsHelperInitOptions | init options} to construct\n * and JSON values.\n */\n public constructor(init?: JsonFsHelperInitOptions) {\n this.config = {\n ...DefaultJsonFsHelperConfig,\n ...(init ?? {})\n };\n }\n\n /**\n * Read type-safe JSON from a file.\n * @param srcPath - Path of the file to read\n * @returns `Success` with a {@link JsonValue | JsonValue} or `Failure`\n * with a message if an error occurs.\n */\n public readJsonFileSync(srcPath: string): Result<JsonValue> {\n return captureResult(() => {\n const fullPath = path.resolve(srcPath);\n const body = fs.readFileSync(fullPath, 'utf8').toString();\n return this.config.json.parse(body) as JsonValue;\n });\n }\n\n /**\n * Read a JSON file and apply a supplied converter or validator.\n * @param srcPath - Path of the file to read.\n * @param cv - Converter or validator used to process the file.\n * @returns `Success` with a result of type `<T>`, or `Failure`\n * with a message if an error occurs.\n */\n public convertJsonFileSync<T, TC = unknown>(\n srcPath: string,\n cv: Converter<T, TC> | Validator<T, TC>,\n context?: TC\n ): Result<T> {\n return this.readJsonFileSync(srcPath).onSuccess((json) => {\n return cv.convert(json, context);\n });\n }\n\n /**\n * Reads all JSON files from a directory and apply a supplied converter or validator.\n * @param srcPath - The path of the folder to be read.\n * @param options - {@link JsonFile.IJsonFsDirectoryOptions | Options} to control\n * conversion and filtering\n */\n public convertJsonDirectorySync<T, TC = unknown>(\n srcPath: string,\n options: IJsonFsDirectoryOptions<T>,\n context?: TC\n ): Result<IReadDirectoryItem<T>[]> {\n return captureResult<IReadDirectoryItem<T>[]>(() => {\n const fullPath = path.resolve(srcPath);\n if (!fs.statSync(fullPath).isDirectory()) {\n throw new Error(`${fullPath}: Not a directory`);\n }\n const files = fs.readdirSync(fullPath, { withFileTypes: true });\n const results = files\n .map((fi) => {\n if (fi.isFile() && this._pathMatchesOptions(options, fi.name)) {\n const filePath = path.resolve(fullPath, fi.name);\n return this.convertJsonFileSync(filePath, options.converter, context)\n .onSuccess((payload) => {\n return succeed({\n filename: fi.name,\n item: payload\n });\n })\n .onFailure((message) => {\n return fail(`${fi.name}: ${message}`);\n });\n }\n return undefined;\n })\n .filter((r): r is Result<IReadDirectoryItem<T>> => r !== undefined);\n return mapResults(results).orThrow();\n });\n }\n\n /**\n * Reads and converts or validates all JSON files from a directory, returning a\n * `Map<string, T>` indexed by file base name (i.e. minus the extension)\n * with an optional name transformation applied if present.\n * @param srcPath - The path of the folder to be read.\n * @param options - {@link JsonFile.IJsonFsDirectoryToMapOptions | Options} to control conversion,\n * filtering and naming.\n */\n public convertJsonDirectoryToMapSync<T, TC = unknown>(\n srcPath: string,\n options: IJsonFsDirectoryToMapOptions<T, TC>,\n context?: unknown\n ): Result<Map<string, T>> {\n return this.convertJsonDirectorySync(srcPath, options, context).onSuccess((items) => {\n const transformName = options.transformName ?? defaultNameTransformer;\n return mapResults(\n items.map((item) => {\n const basename = path.basename(item.filename, '.json');\n return transformName(basename, item.item).onSuccess((name) => {\n return succeed<[string, T]>([name, item.item]);\n });\n })\n ).onSuccess((items) => {\n return succeed(new Map<string, T>(items));\n });\n });\n }\n\n /**\n * Write type-safe JSON to a file.\n * @param srcPath - Path of the file to write.\n * @param value - The {@link JsonValue | JsonValue} to be written.\n */\n public writeJsonFileSync(srcPath: string, value: JsonValue): Result<boolean> {\n return captureResult(() => {\n const fullPath = path.resolve(srcPath);\n const stringified = this.config.json.stringify(value, undefined, 2);\n /* c8 ignore next 3 */\n if (stringified === undefined && this.config.allowUndefinedWrite !== true) {\n throw new Error(`Could not stringify ${value}`);\n }\n fs.writeFileSync(fullPath, stringified!);\n return true;\n });\n }\n\n protected _pathMatchesOptions<T, TC>(options: IJsonFsDirectoryOptions<T, TC>, path: string): boolean {\n /* c8 ignore next 1 */\n const match = options.files ?? this.config.defaultFiles;\n return match.some((m) => m.exec(path));\n }\n}\n\n/**\n * @public\n */\nexport const DefaultJsonFsHelper: JsonFsHelper = new JsonFsHelper();\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonLike.d.ts","sourceRoot":"","sources":["../../../src/packlets/json-file/jsonLike.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpC;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,KAAK,SAAS,CAAC;AAEvE;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,KAAK,SAAS,CAAC;AAEhF;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;AAEpD;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,oBAAoB,GAAG,iBAAiB,CAAC;AAEpE;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,SAAS,CAAC;IACrF,SAAS,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,CAAC,EAAE,YAAY,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;CACnG;AAED;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,SAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonLike.js","sourceRoot":"","sources":["../../../src/packlets/json-file/jsonLike.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAgCH;;GAEG;AACU,QAAA,eAAe,GAAc,IAAI,CAAC","sourcesContent":["/*\n * Copyright (c) 2024 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { JsonValue } from '../json';\n\n/**\n * @public\n */\nexport type JsonReviver = (key: string, value: JsonValue) => JsonValue;\n\n/**\n * @public\n */\nexport type JsonReplacerFunction = (key: string, value: JsonValue) => JsonValue;\n\n/**\n * @public\n */\nexport type JsonReplacerArray = (string | number)[];\n\n/**\n * @public\n */\nexport type JsonReplacer = JsonReplacerFunction | JsonReplacerArray;\n\n/**\n * @public\n */\nexport interface IJsonLike {\n parse(text: string, reviver?: JsonReviver, options?: unknown): JsonValue | undefined;\n stringify(value: JsonValue, replacer?: JsonReplacer, space?: string | number): string | undefined;\n}\n\n/**\n * @public\n */\nexport const DefaultJsonLike: IJsonLike = JSON;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonTreeHelper.d.ts","sourceRoot":"","sources":["../../../src/packlets/json-file/jsonTreeHelper.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAuB,MAAM,eAAe,CAAC;AAClF,OAAO,KAAK,QAAQ,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAmB,SAAS,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD;;;GAGG;AACH,qBAAa,cAAc;IACzB;;OAEG;IACH,SAAgB,IAAI,EAAE,SAAS,CAAC;IAEhC;;;;OAIG;gBACgB,IAAI,CAAC,EAAE,SAAS;IAInC;;;;;;OAMG;IACI,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC;IAOzF;;;;;;;;OAQG;IACI,mBAAmB,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO,EACxC,QAAQ,EAAE,QAAQ,CAAC,QAAQ,EAC3B,QAAQ,EAAE,MAAM,EAChB,EAAE,EAAE,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,EACvC,OAAO,CAAC,EAAE,EAAE,GACX,MAAM,CAAC,CAAC,CAAC;IAMZ;;;;;;;;OAQG;IACI,4BAA4B,CAAC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,CAAC;gBACL,OAAO,IAAA,qBAAU,EAAC,OAAO,CAAC,CAAC;YAC7B,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;OASG;IACI,iCAAiC,CACtC,QAA2B,EAC3B,OAAe,EACf,EAAuC,EACvC,WAAoB,EACpB,OAAY;QAEZ,OAAO,IAAI,CAAC,4BAA4B,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC,SAAS,CAC7F,CAAC,KAAK,EAAE,EAAE;YACR,MAAM,GAAG,GAAG,IAAI,GAAG,EAAa,CAAC;YACjC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;gBACzB,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;gBACtD,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;YAC/B,CAAC;YACD,OAAO,IAAA,kBAAO,EAAC,GAAG,CAAC,CAAC;QACtB,CAAC,CACF,CAAC;IACJ,CAAC;CACF;AAhHD,wCAgHC;AAED;;GAEG;AACU,QAAA,qBAAqB,GAAmB,IAAI,cAAc,EAAE,CAAC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Converter, Result, Validator, mapResults, succeed } from '@fgv/ts-utils';\nimport * as FileTree from '../file-tree';\nimport { JsonValue } from '../json';\nimport { DefaultJsonLike, IJsonLike } from './jsonLike';\nimport { IReadDirectoryItem } from './jsonFsHelper';\n\n/**\n * Helper class to work with JSON files using FileTree API (web-compatible).\n * @public\n */\nexport class JsonTreeHelper {\n /**\n * Configuration for this JsonTreeHelper.\n */\n public readonly json: IJsonLike;\n\n /**\n * Construct a new JsonTreeHelper.\n * @param json - Optional {@link JsonFile.IJsonLike | IJsonLike} used to process strings\n * and JSON values.\n */\n public constructor(json?: IJsonLike) {\n this.json = json ?? DefaultJsonLike;\n }\n\n /**\n * Read type-safe JSON from a file in a FileTree.\n * @param fileTree - The FileTree to read from\n * @param filePath - Path of the file to read within the tree\n * @returns `Success` with a {@link JsonValue | JsonValue} or `Failure`\n * with a message if an error occurs.\n */\n public readJsonFromTree(fileTree: FileTree.FileTree, filePath: string): Result<JsonValue> {\n return fileTree.getFile(filePath).onSuccess((file) => {\n // Now getContents() returns JsonCompatibleType<unknown> which is assignable to JsonValue!\n return file.getContents() as Result<JsonValue>;\n });\n }\n\n /**\n * Read a JSON file from a FileTree and apply a supplied converter or validator.\n * @param fileTree - The FileTree to read from\n * @param filePath - Path of the file to read within the tree\n * @param cv - Converter or validator used to process the file.\n * @param context - Optional context for the converter/validator\n * @returns `Success` with a result of type `<T>`, or `Failure`\n * with a message if an error occurs.\n */\n public convertJsonFromTree<T, TC = unknown>(\n fileTree: FileTree.FileTree,\n filePath: string,\n cv: Converter<T, TC> | Validator<T, TC>,\n context?: TC\n ): Result<T> {\n return this.readJsonFromTree(fileTree, filePath).onSuccess((json) => {\n return cv.convert(json, context);\n });\n }\n\n /**\n * Reads all JSON files from a directory in a FileTree and applies a converter or validator.\n * @param fileTree - The FileTree to read from\n * @param dirPath - The path of the directory within the tree\n * @param cv - Converter or validator to apply to each JSON file\n * @param filePattern - Optional regex pattern to filter files (defaults to .json files)\n * @param context - Optional context for the converter/validator\n * @returns Array of items with filename and converted content\n */\n public convertJsonDirectoryFromTree<T, TC = unknown>(\n fileTree: FileTree.FileTree,\n dirPath: string,\n cv: Converter<T, TC> | Validator<T, TC>,\n filePattern?: RegExp,\n context?: TC\n ): Result<IReadDirectoryItem<T>[]> {\n const pattern = filePattern ?? /\\.json$/;\n\n return fileTree.getDirectory(dirPath).onSuccess((dir) => {\n return dir.getChildren().onSuccess((children) => {\n const results = children\n .filter((child) => child.type === 'file' && pattern.test(child.name))\n .map((file) => {\n return this.convertJsonFromTree(fileTree, file.absolutePath, cv, context).onSuccess((item) => {\n return succeed<IReadDirectoryItem<T>>({\n filename: file.name,\n item\n });\n });\n });\n return mapResults(results);\n });\n });\n }\n\n /**\n * Reads and converts all JSON files from a directory in a FileTree,\n * returning a Map indexed by file base name.\n * @param fileTree - The FileTree to read from\n * @param dirPath - The path of the directory within the tree\n * @param cv - Converter or validator to apply to each JSON file\n * @param filePattern - Optional regex pattern to filter files\n * @param context - Optional context for the converter/validator\n * @returns Map of basename to converted content\n */\n public convertJsonDirectoryToMapFromTree<T, TC = unknown>(\n fileTree: FileTree.FileTree,\n dirPath: string,\n cv: Converter<T, TC> | Validator<T, TC>,\n filePattern?: RegExp,\n context?: TC\n ): Result<Map<string, T>> {\n return this.convertJsonDirectoryFromTree(fileTree, dirPath, cv, filePattern, context).onSuccess(\n (items) => {\n const map = new Map<string, T>();\n for (const item of items) {\n const basename = item.filename.replace(/\\.json$/, '');\n map.set(basename, item.item);\n }\n return succeed(map);\n }\n );\n }\n}\n\n/**\n * @public\n */\nexport const DefaultJsonTreeHelper: JsonTreeHelper = new JsonTreeHelper();\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/validators/index.ts"],"names":[],"mappings":"AAsBA,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/validators/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;AAEH,+CAA6B","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nexport * from './validators';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../../src/packlets/validators/validators.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAW,UAAU,EAAE,SAAS,EAAQ,MAAM,eAAe,CAAC;AACrE,OAAO,EAA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U,CAAC,OAAO,CAAC,eAAe,EAAiC,CAAC;AAE1E;;;;GAIG;AACU,QAAA,OAAO,GAClB,IAAI,qBAAU,CAAC,OAAO,CAAC,gBAAgB,EAAyB,CAAC;AAEnE;;;;;GAKG;AACH,SAAgB,OAAO,CAAI,KAAQ;IACjC,OAAO,IAAI,qBAAU,CAAC,IAAI,CAAC,gBAAgB,CAA2B;QACpE,SAAS,EAAE,CAAC,IAAa,EAAwB,EAAE;YACjD,OAAO,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAA,eAAI,EAAC,oBAAoB,MAAM,CAAC,KAAK,CAAC,WAAW,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC1G,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,SAAgB,eAAe,CAC7B,MAAwB,EACxB,OAAgB;IAEhB,OAAO,IAAI,qBAAU,CAAC,IAAI,CAAC,gBAAgB,CAA8C;QACvF,SAAS,EAAE,CAAC,IAAa,EAAE,OAAkD,EAAwB,EAAE;YACrG,MAAM,eAAe,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAE,OAA4B,CAAC,CAAC,CAAC,MAAM,CAAC;YACxF,MAAM,KAAK,GAAG,eAAe,CAAC,OAAO,CAAC,IAAS,CAAC,CAAC;YACjD,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;gBACf,OAAO,IAAI,CAAC;YACd,CAAC;YACD,OAAO,IAAA,eAAI,EAAC,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,4BAA4B,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC7E,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["/*\n * Copyright (c) 2023 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Failure, Validation, Validator, fail } from '@fgv/ts-utils';\nimport { JsonArray, JsonObject, JsonPrimitive, JsonValue, isJsonArray, isJsonObject } from '../json';\n\n/* eslint-disable @typescript-eslint/no-use-before-define */\n\n/**\n * Validation context for in-place JSON validators.\n * @public\n */\nexport interface IJsonValidatorContext {\n ignoreUndefinedProperties?: boolean;\n}\n\n/**\n * An in-place validator which validates that a supplied `unknown` value is\n * a valid {@link JsonPrimitive | JsonPrimitive}.\n * @public\n */\nexport const jsonPrimitive: Validator<JsonPrimitive, IJsonValidatorContext> =\n new Validation.Base.GenericValidator({\n validator: (\n from: unknown,\n ctx?: IJsonValidatorContext,\n self?: Validator<JsonPrimitive, IJsonValidatorContext>\n ): boolean | Failure<JsonPrimitive> => {\n if (from === null) {\n return true;\n }\n switch (typeof from) {\n case 'boolean':\n case 'string':\n return true;\n case 'number':\n if (!Number.isNaN(from)) {\n return true;\n }\n break;\n }\n if (from === undefined && ctx?.ignoreUndefinedProperties === true) {\n return true;\n }\n return fail(`\"${String(from)}\": invalid JSON primitive.`);\n }\n });\n\n/**\n * An in-place validator which validates that a supplied `unknown` value is\n * a valid {@link JsonObject | JsonObject}. Fails by default if any properties or array elements\n * are `undefined` - this default behavior can be overridden by supplying an appropriate\n * {@link Validators.IJsonValidatorContext | context} at runtime.\n * @public\n */\nexport const jsonObject: Validator<JsonObject, IJsonValidatorContext> = new Validation.Base.GenericValidator({\n validator: (\n from: unknown,\n ctx?: IJsonValidatorContext,\n self?: Validator<JsonObject, IJsonValidatorContext>\n ) => {\n if (!isJsonObject(from)) {\n return fail('invalid JSON object.');\n }\n const errors: string[] = [];\n for (const [name, value] of Object.entries(from)) {\n jsonValue.validate(value, ctx).onFailure((m) => {\n errors.push(`${name}: ${m}`);\n return fail(m);\n });\n }\n if (errors.length > 0) {\n return fail(`invalid JSON object:\\n${errors.join('\\n')}`);\n }\n return true;\n }\n});\n\n/**\n * An in-place validator which validates that a supplied `unknown` value is\n * a valid {@link JsonArray | JsonArray}. Fails by default if any properties or array elements\n * are `undefined` - this default behavior can be overridden by supplying an appropriate\n * {@link Validators.IJsonValidatorContext | context} at runtime.\n * @public\n */\nexport const jsonArray: Validator<JsonArray, IJsonValidatorContext> = new Validation.Base.GenericValidator({\n validator: (\n from: unknown,\n ctx?: IJsonValidatorContext,\n self?: Validator<JsonArray, IJsonValidatorContext>\n ) => {\n if (!isJsonArray(from)) {\n return fail('not an array');\n }\n const errors: string[] = [];\n for (let i = 0; i < from.length; i++) {\n const value = from[i];\n jsonValue.validate(value, ctx).onFailure((m) => {\n errors.push(`${i}: ${m}`);\n return fail(m);\n });\n }\n if (errors.length > 0) {\n return fail(`array contains non-json elements:\\n${errors.join('\\n')}`);\n }\n return true;\n }\n});\n\n/**\n * An in-place validator which validates that a supplied `unknown` value is\n * a valid {@link JsonValue | JsonValue}. Fails by default if any properties or array elements\n * are `undefined` - this default behavior can be overridden by supplying an appropriate\n * {@link Validators.IJsonValidatorContext | context} at runtime.\n * @public\n */\nexport const jsonValue: Validator<JsonValue, IJsonValidatorContext> = new Validation.Base.GenericValidator<\n JsonValue,\n IJsonValidatorContext\n>({\n validator: (\n from: unknown,\n ctx?: IJsonValidatorContext,\n self?: Validator<JsonValue, IJsonValidatorContext>\n ) => {\n if (isJsonArray(from)) {\n const result = jsonArray.validate(from, ctx);\n return result.success === true ? true : result;\n } else if (isJsonObject(from)) {\n const result = jsonObject.validate(from, ctx);\n return result.success === true ? true : result;\n }\n const result = jsonPrimitive.validate(from, ctx);\n return result.success === true ? true : result;\n }\n});\n\n/**\n * A `StringValidator` which validates a string in place.\n * Accepts {@link Validators.IJsonValidatorContext | IJsonValidatorContext} but ignores it.\n * @public\n */\nexport const string: Validation.Classes.StringValidator<string, IJsonValidatorContext> =\n new Validation.Classes.StringValidator<string, IJsonValidatorContext>();\n\n/**\n * A `NumberValidator` which validates a number in place.\n * Accepts {@link Validators.IJsonValidatorContext | IJsonValidatorContext} but ignores it.\n * @public\n */\nexport const number: Validation.Classes.NumberValidator<number, IJsonValidatorContext> =\n new Validation.Classes.NumberValidator<number, IJsonValidatorContext>();\n\n/**\n * A `BooleanValidator` which validates a boolean in place.\n * Accepts `IJsonValidatorContext` but ignores it.\n * @public\n */\nexport const boolean: Validator<boolean, IJsonValidatorContext> =\n new Validation.Classes.BooleanValidator<IJsonValidatorContext>();\n\n/**\n * Helper to create a validator for a literal value.\n * Accepts `IJsonValidatorContext` but ignores it.\n * Mirrors the behavior of `@fgv/ts-utils`.\n * @public\n */\nexport function literal<T>(value: T): Validator<T, IJsonValidatorContext> {\n return new Validation.Base.GenericValidator<T, IJsonValidatorContext>({\n validator: (from: unknown): boolean | Failure<T> => {\n return from === value ? true : fail(`Expected literal ${String(value)}, found ${JSON.stringify(from)}`);\n }\n });\n}\n\n/**\n * Helper function to create a `Validator` which validates `unknown` to one of a set of\n * supplied enumerated values. Anything else fails.\n *\n * @remarks\n * This JSON variant accepts an `IJsonValidatorContext` OR\n * a `ReadonlyArray<T>` as its validation context. If the context is an array, it is used to override the\n * allowed values for that validation; otherwise, the original `values` supplied at creation time are used.\n *\n * @param values - Array of allowed values.\n * @param message - Optional custom failure message.\n * @returns A new `Validator` returning `<T>`.\n * @public\n */\nexport function enumeratedValue<T>(\n values: ReadonlyArray<T>,\n message?: string\n): Validator<T, IJsonValidatorContext | ReadonlyArray<T>> {\n return new Validation.Base.GenericValidator<T, IJsonValidatorContext | ReadonlyArray<T>>({\n validator: (from: unknown, context?: IJsonValidatorContext | ReadonlyArray<T>): boolean | Failure<T> => {\n const effectiveValues = Array.isArray(context) ? (context as ReadonlyArray<T>) : values;\n const index = effectiveValues.indexOf(from as T);\n if (index >= 0) {\n return true;\n }\n return fail(message ?? `Invalid enumerated value ${JSON.stringify(from)}`);\n }\n });\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fgv/ts-json-base",
|
|
3
|
-
"version": "5.1.0-
|
|
3
|
+
"version": "5.1.0-20",
|
|
4
4
|
"description": "Typescript types and basic functions for working with json",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "dist/ts-json-base.d.ts",
|
|
@@ -17,17 +17,6 @@
|
|
|
17
17
|
"types": "./dist/ts-json-base.d.ts"
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
|
-
"scripts": {
|
|
21
|
-
"build": "heft build --clean",
|
|
22
|
-
"clean": "heft clean",
|
|
23
|
-
"test": "heft test --clean",
|
|
24
|
-
"build-docs": "typedoc --options ./config/typedoc.json",
|
|
25
|
-
"build-all": "rushx build; rushx build-docs",
|
|
26
|
-
"test-handles": "jest --runInBand --detectOpenHandles",
|
|
27
|
-
"clean-jest": "jest --clear-cache",
|
|
28
|
-
"lint": "eslint src --ext .ts",
|
|
29
|
-
"fixlint": "eslint src --ext .ts --fix"
|
|
30
|
-
},
|
|
31
20
|
"keywords": [
|
|
32
21
|
"typescript",
|
|
33
22
|
"json"
|
|
@@ -40,8 +29,6 @@
|
|
|
40
29
|
"homepage": "https://github.com/ErikFortune/fgv/tree/main/libraries/ts-json-base#readme",
|
|
41
30
|
"sideEffects": false,
|
|
42
31
|
"devDependencies": {
|
|
43
|
-
"@fgv/ts-utils": "workspace:*",
|
|
44
|
-
"@fgv/ts-utils-jest": "workspace:*",
|
|
45
32
|
"@types/jest": "^29.5.14",
|
|
46
33
|
"@types/node": "^20.14.9",
|
|
47
34
|
"@typescript-eslint/eslint-plugin": "^8.52.0",
|
|
@@ -57,7 +44,7 @@
|
|
|
57
44
|
"ts-node": "^10.9.2",
|
|
58
45
|
"typescript": "5.9.3",
|
|
59
46
|
"eslint-plugin-n": "^17.23.1",
|
|
60
|
-
"@rushstack/heft": "1.2.
|
|
47
|
+
"@rushstack/heft": "1.2.7",
|
|
61
48
|
"@rushstack/heft-jest-plugin": "1.2.6",
|
|
62
49
|
"@types/heft-jest": "1.0.6",
|
|
63
50
|
"@microsoft/api-documenter": "^7.28.2",
|
|
@@ -65,12 +52,16 @@
|
|
|
65
52
|
"@rushstack/eslint-config": "4.6.4",
|
|
66
53
|
"eslint-plugin-tsdoc": "~0.5.2",
|
|
67
54
|
"@types/luxon": "^3.7.1",
|
|
68
|
-
"@
|
|
69
|
-
"@
|
|
70
|
-
"
|
|
55
|
+
"@rushstack/heft-node-rig": "2.11.27",
|
|
56
|
+
"@microsoft/api-extractor": "^7.55.2",
|
|
57
|
+
"typedoc": "~0.28.16",
|
|
58
|
+
"@fgv/ts-utils": "5.1.0-20",
|
|
59
|
+
"@fgv/ts-utils-jest": "5.1.0-20",
|
|
60
|
+
"@fgv/heft-dual-rig": "5.1.0-20",
|
|
61
|
+
"@fgv/typedoc-compact-theme": "5.1.0-20"
|
|
71
62
|
},
|
|
72
63
|
"peerDependencies": {
|
|
73
|
-
"@fgv/ts-utils": "
|
|
64
|
+
"@fgv/ts-utils": "5.1.0-20"
|
|
74
65
|
},
|
|
75
66
|
"dependencies": {
|
|
76
67
|
"luxon": "^3.7.2"
|
|
@@ -78,5 +69,16 @@
|
|
|
78
69
|
"repository": {
|
|
79
70
|
"type": "git",
|
|
80
71
|
"url": "https://github.com/ErikFortune/fgv.git"
|
|
72
|
+
},
|
|
73
|
+
"scripts": {
|
|
74
|
+
"build": "heft build --clean",
|
|
75
|
+
"clean": "heft clean",
|
|
76
|
+
"test": "heft test --clean",
|
|
77
|
+
"build-docs": "typedoc --options ./config/typedoc.json",
|
|
78
|
+
"build-all": "rushx build; rushx build-docs",
|
|
79
|
+
"test-handles": "jest --runInBand --detectOpenHandles",
|
|
80
|
+
"clean-jest": "jest --clear-cache",
|
|
81
|
+
"lint": "eslint src --ext .ts",
|
|
82
|
+
"fixlint": "eslint src --ext .ts --fix"
|
|
81
83
|
}
|
|
82
|
-
}
|
|
84
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{ "name": "test", "enabled": true }
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
[1, 2, 3]
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2025 Erik Fortune
|
|
3
|
-
*
|
|
4
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
-
* in the Software without restriction, including without limitation the rights
|
|
7
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
-
* furnished to do so, subject to the following conditions:
|
|
10
|
-
*
|
|
11
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
-
* copies or substantial portions of the Software.
|
|
13
|
-
*
|
|
14
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
-
* SOFTWARE.
|
|
21
|
-
*/
|
|
22
|
-
// Factory helpers for runtime sections
|
|
23
|
-
export function makeUser(overrides = {}) {
|
|
24
|
-
return Object.assign({ id: 'u1', name: 'Test User', tags: ['a', 'b'], meta: { active: true, score: 10 } }, overrides);
|
|
25
|
-
}
|
|
26
|
-
export function makeAlpha() {
|
|
27
|
-
return { kind: 'alpha', value: 'ok' };
|
|
28
|
-
}
|
|
29
|
-
export function makeBeta() {
|
|
30
|
-
return { kind: 'beta', count: 3 };
|
|
31
|
-
}
|
|
32
|
-
//# sourceMappingURL=helpers.js.map
|