zcb 0.2.4 → 0.2.6
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/README.md +15 -3
- package/dist/cjs/cli.cjs +1 -185
- package/dist/cjs/cli.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -384
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/cli.mjs +1 -182
- package/dist/esm/cli.mjs.map +1 -1
- package/dist/esm/index.mjs +1 -372
- package/dist/esm/index.mjs.map +1 -1
- package/dist/production.analysis.txt +72 -0
- package/dist/types/cjs/createConfigParser.d.cts +1 -1
- package/dist/types/cjs/createConfigParser.d.cts.map +1 -1
- package/dist/types/cjs/createConfigReader.d.cts +6 -3
- package/dist/types/cjs/createConfigReader.d.cts.map +1 -1
- package/dist/types/cjs/types.d.cts +2 -2
- package/dist/types/cjs/types.d.cts.map +1 -1
- package/dist/types/cjs/utils/arrayHasInvalidDefaults.d.cts +1 -1
- package/dist/types/cjs/utils/arrayHasInvalidDefaults.d.cts.map +1 -1
- package/dist/types/cjs/utils/collateObjectPropertyDefaults.d.cts +2 -2
- package/dist/types/cjs/utils/collateObjectPropertyDefaults.d.cts.map +1 -1
- package/dist/types/cjs/utils/importValidateTransformWriteConfig.d.cts +1 -1
- package/dist/types/cjs/utils/importValidateTransformWriteConfig.d.cts.map +1 -1
- package/dist/types/cjs/utils/isSchemaValid.d.cts +1 -1
- package/dist/types/cjs/utils/isSchemaValid.d.cts.map +1 -1
- package/dist/types/cjs/utils/isValidPropertyDefinition.d.cts +1 -1
- package/dist/types/cjs/utils/isValidPropertyDefinition.d.cts.map +1 -1
- package/dist/types/cjs/utils/jsonStringifyReplacer.d.cts +1 -1
- package/dist/types/cjs/utils/jsonStringifyReplacer.d.cts.map +1 -1
- package/dist/types/cjs/utils/objectPropertyHasDefaults.d.cts +1 -1
- package/dist/types/cjs/utils/objectPropertyHasDefaults.d.cts.map +1 -1
- package/dist/types/cjs/utils/recordHasInvalidDefaults.d.cts +1 -1
- package/dist/types/cjs/utils/recordHasInvalidDefaults.d.cts.map +1 -1
- package/dist/types/cjs/utils/transformWriteConfig.d.cts +1 -1
- package/dist/types/cjs/utils/transformWriteConfig.d.cts.map +1 -1
- package/dist/types/esm/createConfigParser.d.ts +1 -1
- package/dist/types/esm/createConfigParser.d.ts.map +1 -1
- package/dist/types/esm/createConfigReader.d.ts +6 -3
- package/dist/types/esm/createConfigReader.d.ts.map +1 -1
- package/dist/types/esm/types.d.ts +2 -2
- package/dist/types/esm/types.d.ts.map +1 -1
- package/dist/types/esm/utils/arrayHasInvalidDefaults.d.ts +1 -1
- package/dist/types/esm/utils/arrayHasInvalidDefaults.d.ts.map +1 -1
- package/dist/types/esm/utils/collateObjectPropertyDefaults.d.ts +2 -2
- package/dist/types/esm/utils/collateObjectPropertyDefaults.d.ts.map +1 -1
- package/dist/types/esm/utils/importValidateTransformWriteConfig.d.ts +1 -1
- package/dist/types/esm/utils/importValidateTransformWriteConfig.d.ts.map +1 -1
- package/dist/types/esm/utils/isSchemaValid.d.ts +1 -1
- package/dist/types/esm/utils/isSchemaValid.d.ts.map +1 -1
- package/dist/types/esm/utils/isValidPropertyDefinition.d.ts +1 -1
- package/dist/types/esm/utils/isValidPropertyDefinition.d.ts.map +1 -1
- package/dist/types/esm/utils/jsonStringifyReplacer.d.ts +1 -1
- package/dist/types/esm/utils/jsonStringifyReplacer.d.ts.map +1 -1
- package/dist/types/esm/utils/objectPropertyHasDefaults.d.ts +1 -1
- package/dist/types/esm/utils/objectPropertyHasDefaults.d.ts.map +1 -1
- package/dist/types/esm/utils/recordHasInvalidDefaults.d.ts +1 -1
- package/dist/types/esm/utils/recordHasInvalidDefaults.d.ts.map +1 -1
- package/dist/types/esm/utils/transformWriteConfig.d.ts +1 -1
- package/dist/types/esm/utils/transformWriteConfig.d.ts.map +1 -1
- package/dist/types/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +22 -32
- package/src/__testUtils__/builtConfig.ts +1 -0
- package/src/createConfigParser.ts +1 -1
- package/src/createConfigReader.test.ts +28 -0
- package/src/createConfigReader.ts +25 -5
- package/src/types.ts +2 -2
- package/src/utils/arrayHasInvalidDefaults.ts +1 -1
- package/src/utils/collateObjectPropertyDefaults.ts +2 -2
- package/src/utils/importValidateTransformWriteConfig.ts +3 -3
- package/src/utils/isSchemaValid.ts +1 -1
- package/src/utils/isValidPropertyDefinition.ts +1 -1
- package/src/utils/jsonStringifyReplacer.ts +1 -1
- package/src/utils/objectPropertyHasDefaults.ts +1 -1
- package/src/utils/recordHasInvalidDefaults.ts +1 -1
- package/src/utils/transformWriteConfig.ts +1 -1
package/dist/esm/cli.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.mjs","sources":["../zod-config-builder/src//types.ts","../zod-config-builder/src//transformers/removeDisabledSlices.ts","../zod-config-builder/src//transformers/setupExperiments.ts","../zod-config-builder/src//utils/transformConfig.ts","../zod-config-builder/src//utils/transformWriteConfig.ts","../zod-config-builder/src//utils/importValidateTransformWriteConfig.ts","../zod-config-builder/src//cli.ts"],"sourcesContent":["import type { List } from 'ts-toolbelt';\nimport type { Includes, Join } from 'type-fest';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyRecord = Record<string, any>;\n\nexport type Buckets<Config extends AnyRecord> = Record<string, Experiment<Config>>;\n\nexport interface ConfigParserOptions {\n experimentsCallback?: RunExperimentsCallback;\n}\n\nexport interface Experiment<Config extends AnyRecord> {\n action?: TransformConfigHandlerAction;\n value?: Config;\n}\n\nexport enum NonEmumeralProperties {\n CALLBACKS = '__callbacks',\n DISABLED = '__disabled',\n EXPERIMENT = '__experiment',\n ID = '__id',\n TYPE = '__type',\n ZCB = '__zcb',\n}\n\nexport type Path<Config extends object> = Join<Leaves<Config>, '.'>;\n\nexport type RunExperimentsCallback = (id: string) => Promise<string>;\n\nexport type Scope<Config extends object> = Join<Paths<Config>, '.'>;\n\nexport type SetupExperimentsCallback = <Config extends AnyRecord>(\n id: string,\n clone: Config,\n config: Config\n) => Promise<Buckets<Config>>;\n\nexport type TransformConfigHandler = <Config extends AnyRecord>(\n clone: Config,\n config: Config\n) => TransformConfigHandlerReturnType<Config> | Promise<TransformConfigHandlerReturnType<Config>>;\n\nexport type TransformConfigHandlerSync = <Config extends AnyRecord>(\n clone: Config,\n config: Config\n) => TransformConfigHandlerReturnType<Config>;\n\nexport enum TransformConfigHandlerAction {\n DELETE_NODE = 'deleteNode',\n SKIP_NODE = 'skipNode',\n}\n\nexport interface TransformConfigHandlerReturnType<Config extends AnyRecord> {\n action?: TransformConfigHandlerAction;\n value?: Config;\n}\n\nexport interface WriteConfigOptions {\n experimentsCallback?: SetupExperimentsCallback;\n outputFile: string;\n}\n\nexport type Leaves<T, LeafPath extends string[] = []> = T extends string\n ? LeafPath\n : {\n [K in keyof T & string]: Leaves<T[K], [...LeafPath, K]>;\n }[keyof T & string];\n\nexport type Paths<T, LeafPath extends string[] = []> = T extends string\n ? LeafPath\n : {\n [K in keyof T & string]: T[K] extends object ? Paths<T[K], [...LeafPath, K]> : LeafPath;\n }[keyof T & string];\n\nexport type LeavesScopeDiffs<T1 extends readonly string[][], T2 extends string[]> = {\n [K1 in keyof T1]: List.Length<List.Intersect<T1[K1], T2, '<-contains'>> extends 1\n ? List.Length<T1[K1]> extends 1\n ? Includes<T2, T1[K1][0]> extends false\n ? T1[K1]\n : never\n : List.Diff<T1[K1], T2>\n : never;\n}[number];\n","import {\n type AnyRecord,\n NonEmumeralProperties,\n TransformConfigHandlerAction,\n type TransformConfigHandlerSync,\n} from '../types.ts';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const removeDisabledSlices: TransformConfigHandlerSync = <Config extends AnyRecord>(\n clone: Config,\n config: Config\n) => {\n if (NonEmumeralProperties.DISABLED in config) {\n return {\n action: TransformConfigHandlerAction.DELETE_NODE,\n };\n }\n\n return {\n value: clone,\n };\n};\n","import {\n type AnyRecord,\n NonEmumeralProperties,\n type SetupExperimentsCallback,\n type TransformConfigHandler,\n} from '../types.ts';\n\nexport const setupExperiments =\n (callback: SetupExperimentsCallback): TransformConfigHandler =>\n async <Config extends AnyRecord>(clone: Config, config: Config) => {\n if (NonEmumeralProperties.EXPERIMENT in config && typeof config.__experiment === 'string') {\n const buckets = await callback(config.__experiment, clone, config);\n\n // @ts-expect-error private property\n clone.__experiment = {\n buckets,\n id: config.__experiment,\n };\n\n return {\n value: clone,\n };\n }\n\n return {\n value: clone,\n };\n };\n","import { castArray, isPlainObject } from 'lodash-es';\nimport {\n type AnyRecord,\n type TransformConfigHandler,\n TransformConfigHandlerAction,\n type TransformConfigHandlerSync,\n} from '../types.ts';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst transformArray = (list: any[], handler: TransformConfigHandler | TransformConfigHandler[]): Promise<any[]> =>\n Promise.all(\n list.map(entry => {\n if (isPlainObject(entry)) {\n return transformConfig(entry, handler);\n }\n\n if (Array.isArray(entry)) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return transformArray(entry, handler);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return entry;\n })\n );\n\nexport const transformConfig = async <Config extends AnyRecord>(\n config: Config,\n handler: TransformConfigHandler | TransformConfigHandler[] = []\n): Promise<Config> => {\n let transform = {} as Config;\n const handlers = castArray(handler);\n\n for (const callback of handlers) {\n const result = await Promise.resolve(callback(transform, config));\n\n if (result.action === TransformConfigHandlerAction.DELETE_NODE) {\n return {} as Config;\n }\n\n if (result.value) {\n transform = result.value;\n }\n\n if (result.action === TransformConfigHandlerAction.SKIP_NODE) {\n return transform;\n }\n }\n\n for (const key in config) {\n const value = config[key];\n\n if (isPlainObject(value)) {\n transform[key] = await transformConfig(value, handler);\n } else if (Array.isArray(value)) {\n transform[key] = (await transformArray(value, handler)) as Config[Extract<keyof Config, string>];\n } else {\n transform[key] = value;\n }\n }\n\n return transform;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst transformArraySync = (list: any[], handler: TransformConfigHandlerSync | TransformConfigHandlerSync[]): any[] =>\n list.map(entry => {\n if (isPlainObject(entry)) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return transformConfigSync(entry, handler);\n }\n\n if (Array.isArray(entry)) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return transformArraySync(entry, handler);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return entry;\n });\n\nexport const transformConfigSync = <Config extends AnyRecord>(\n config: Config,\n handler: TransformConfigHandlerSync | TransformConfigHandlerSync[] = []\n): Config => {\n let transform = {} as Config;\n const handlers = castArray(handler);\n\n for (const callback of handlers) {\n const result = callback(transform, config);\n\n if (result.action === TransformConfigHandlerAction.DELETE_NODE) {\n return {} as Config;\n }\n\n if (result.value) {\n transform = result.value;\n }\n\n if (result.action === TransformConfigHandlerAction.SKIP_NODE) {\n return transform;\n }\n }\n\n for (const key in config) {\n const value = config[key];\n\n if (isPlainObject(value)) {\n transform[key] = transformConfigSync(value, handler);\n } else if (Array.isArray(value)) {\n transform[key] = transformArraySync(value, handler) as Config[Extract<keyof Config, string>];\n } else {\n transform[key] = value;\n }\n }\n\n return transform;\n};\n","import { outputFileSync } from 'fs-extra/esm';\nimport Handlebars from 'handlebars';\nimport { readFileSync } from 'node:fs';\nimport { dirname, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport shelljs from 'shelljs';\nimport { removeDisabledSlices } from '../transformers/removeDisabledSlices.ts';\nimport { setupExperiments } from '../transformers/setupExperiments.ts';\nimport type { TransformConfigHandler, WriteConfigOptions } from '../types.ts';\nimport { transformConfig } from './transformConfig.ts';\n\nexport const transformWriteConfig = async <Config extends object>(\n config: Config,\n { experimentsCallback, outputFile }: WriteConfigOptions\n) => {\n const handlers: TransformConfigHandler[] = [removeDisabledSlices];\n\n if (experimentsCallback) {\n handlers.push(setupExperiments(experimentsCallback));\n }\n\n const template = Handlebars.compile(\n readFileSync(resolve(dirname(fileURLToPath(import.meta.url)), './templates/config.ts.hbs'), { encoding: 'utf8' })\n );\n\n const output = template({ config: JSON.stringify(await transformConfig(config, handlers), undefined, 2) }).replaceAll(\n /\"([A-Za-z][\\dA-Za-z]+)\":/g,\n '$1:'\n );\n\n shelljs.echo(`zcd watch => writing to file: ${outputFile}`);\n shelljs.echo(`zcd watch => content to write:\\n${output}\\n`);\n outputFileSync(resolve(process.cwd(), outputFile), output);\n};\n","import { resolve } from 'node:path';\nimport shelljs from 'shelljs';\nimport type { Commands } from '../cli.ts';\nimport type { ConfigBuilder } from '../createConfigBuilder.ts';\nimport type { SetupExperimentsCallback } from '../types.ts';\nimport { transformWriteConfig } from './transformWriteConfig.ts';\n\nexport const importValidateTransformWriteConfig = (\n inputFile: string,\n outputFile: string,\n command: Commands,\n experimentCallbackFile?: string\n) => {\n import(resolve(process.cwd(), inputFile))\n .then(({ default: configBuilder }: { default: ConfigBuilder<object> }) => {\n if (!configBuilder.$validate()) {\n shelljs.echo(`zcd ${command} => invalid config`);\n shelljs.echo(`zcd ${command} => config values:\\n${configBuilder.$toJson()}\\n`);\n shelljs.echo(`zcd ${command} => errors:\\n${JSON.stringify(configBuilder.$errors(), undefined, 2)}\\n`);\n shelljs.exit(1);\n }\n\n shelljs.echo('zcd ${command} => valid config');\n shelljs.echo(`zcd ${command} => config values:\\n${configBuilder.$toJson()}\\n`);\n\n if (experimentCallbackFile) {\n import(resolve(process.cwd(), experimentCallbackFile))\n .then(({ default: experimentsCallback }: { default: SetupExperimentsCallback }) => {\n void transformWriteConfig(configBuilder.$values(), { experimentsCallback, outputFile });\n })\n .catch((error: unknown) => {\n if (error instanceof Error) {\n shelljs.echo(`zcd ${command} => error message: ${error.message}`);\n\n if (error.stack) {\n shelljs.echo(`zcd ${command} => error stack:\\n${error.stack}\\n`);\n }\n }\n });\n\n return;\n }\n\n void transformWriteConfig(configBuilder.$values(), { outputFile });\n })\n .catch((error: unknown) => {\n if (error instanceof Error) {\n shelljs.echo(`zcd ${command} => error message: ${error.message}`);\n\n if (error.stack) {\n shelljs.echo(`zcd ${command} => error stack:\\n${error.stack}\\n`);\n }\n }\n });\n};\n","import { watchFile } from 'node:fs';\nimport { resolve } from 'node:path';\nimport shelljs from 'shelljs';\nimport yargs from 'yargs';\nimport { importValidateTransformWriteConfig } from './utils/importValidateTransformWriteConfig.ts';\n\nexport enum Commands {\n BUILD = 'build',\n WATCH = 'watch',\n}\n\nconst generateArguments = (cmdYargs: yargs.Argv) =>\n cmdYargs\n .positional('input-file', {\n demandOption: true,\n desc: 'The relative path to the config builder root file',\n type: 'string',\n })\n .positional('output-file', {\n demandOption: true,\n desc: 'The relative path to the output config file',\n type: 'string',\n })\n .option('experiments-callback-file', {\n desc: 'The relative path to the experiment callback file',\n type: 'string',\n });\n\nexport const cli = () => {\n yargs\n .command(\n 'watch <input-file> <output-file>',\n 'Watch a config builder and write config',\n cmdYargs => generateArguments(cmdYargs),\n argv => {\n shelljs.echo(`zcd watch => watching file: ${argv['input-file']}`);\n\n watchFile(resolve(process.cwd(), argv['input-file']), () => {\n shelljs.echo('zcd watch => file change detected');\n\n importValidateTransformWriteConfig(\n argv['input-file'],\n argv['output-file'],\n Commands.WATCH,\n argv['experiments-callback-file']\n );\n });\n }\n )\n .command(\n 'build <input-file> <output-file>',\n 'Write config from a config builder',\n cmdYargs => generateArguments(cmdYargs),\n argv => {\n shelljs.echo(`zcd build => building file: ${argv['input-file']}`);\n\n importValidateTransformWriteConfig(\n argv['input-file'],\n argv['output-file'],\n Commands.BUILD,\n argv['experiments-callback-file']\n );\n }\n )\n .help().argv;\n};\n"],"names":["NonEmumeralProperties","TransformConfigHandlerAction","removeDisabledSlices","clone","config","DISABLED","action","DELETE_NODE","value","setupExperiments","callback","EXPERIMENT","__experiment","buckets","id","transformArray","list","handler","Promise","all","map","entry","isPlainObject","transformConfig","Array","isArray","transform","handlers","castArray","result","resolve","SKIP_NODE","key","transformWriteConfig","experimentsCallback","outputFile","push","template","Handlebars","compile","readFileSync","dirname","fileURLToPath","import","meta","url","encoding","output","JSON","stringify","undefined","replaceAll","shelljs","echo","outputFileSync","process","cwd","importValidateTransformWriteConfig","inputFile","command","experimentCallbackFile","then","default","configBuilder","$validate","$toJson","$errors","exit","$values","catch","error","Error","message","stack","Commands","generateArguments","cmdYargs","positional","demandOption","desc","type","option","cli","yargs","argv","watchFile","WATCH","BUILD","help"],"mappings":";;;;;;;;;;AAiBYA,IAAAA,qBAAqB,aAArBA,qBAAqB,EAAA;EAArBA,qBAAqB,CAAA,WAAA,CAAA,GAAA,aAAA,CAAA;EAArBA,qBAAqB,CAAA,UAAA,CAAA,GAAA,YAAA,CAAA;EAArBA,qBAAqB,CAAA,YAAA,CAAA,GAAA,cAAA,CAAA;EAArBA,qBAAqB,CAAA,IAAA,CAAA,GAAA,MAAA,CAAA;EAArBA,qBAAqB,CAAA,MAAA,CAAA,GAAA,QAAA,CAAA;EAArBA,qBAAqB,CAAA,KAAA,CAAA,GAAA,OAAA,CAAA;AAAA,EAAA,OAArBA,qBAAqB,CAAA;AAAA,CAAA,CAAA,EAAA,CAAA,CAAA;AA+BrBC,IAAAA,4BAA4B,aAA5BA,4BAA4B,EAAA;EAA5BA,4BAA4B,CAAA,aAAA,CAAA,GAAA,YAAA,CAAA;EAA5BA,4BAA4B,CAAA,WAAA,CAAA,GAAA,UAAA,CAAA;AAAA,EAAA,OAA5BA,4BAA4B,CAAA;AAAA,CAAA,CAAA,EAAA,CAAA;;ACxCjC,MAAMC,oBAAgD,GAAGA,CAC9DC,KAAa,EACbC,MAAc,KACX;AACH,EAAA,IAAIJ,qBAAqB,CAACK,QAAQ,IAAID,MAAM,EAAE;IAC5C,OAAO;MACLE,MAAM,EAAEL,4BAA4B,CAACM,WAAAA;KACtC,CAAA;AACH,GAAA;EAEA,OAAO;AACLC,IAAAA,KAAK,EAAEL,KAAAA;GACR,CAAA;AACH,CAAC;;ACdM,MAAMM,gBAAgB,GAC1BC,QAAkC,IACnC,OAAiCP,KAA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C,EAAAA,IAAI,EAAE,QAAA;AACR,CAAC,CAAC,CAAA;AAEOE,MAAAA,GAAG,GAAGA,MAAM;AACvBC,EAAAA,KAAK,CACFxB,OAAO,CACN,kCAAkC,EAClC,yCAAyC,EACzCiB,QAAQ,IAAID,iBAAiB,CAACC,QAAQ,CAAC,EACvCQ,IAAI,IAAI;IACNhC,OAAO,CAACC,IAAI,CAAE,CAAA,4BAAA,EAA8B+B,IAAI,CAAC,YAAY,CAAE,CAAA,CAAC,CAAC,CAAA;AAEjEC,IAAAA,SAAS,CAACvD,OAAO,CAACyB,OAAO,CAACC,GAAG,EAAE,EAAE4B,IAAI,CAAC,YAAY,CAAC,CAAC,EAAE,MAAM;AAC1DhC,MAAAA,OAAO,CAACC,IAAI,CAAC,mCAAmC,CAAC,CAAA;AAEjDI,MAAAA,kCAAkC,CAChC2B,IAAI,CAAC,YAAY,CAAC,EAClBA,IAAI,CAAC,aAAa,CAAC,EACnBV,QAAQ,CAACY,KAAK,EACdF,IAAI,CAAC,2BAA2B,CAClC,CAAC,CAAA;AACH,KAAC,CAAC,CAAA;AACJ,GACF,CAAC,CACAzB,OAAO,CACN,kCAAkC,EAClC,oCAAoC,EACpCiB,QAAQ,IAAID,iBAAiB,CAACC,QAAQ,CAAC,EACvCQ,IAAI,IAAI;IACNhC,OAAO,CAACC,IAAI,CAAE,CAAA,4BAAA,EAA8B+B,IAAI,CAAC,YAAY,CAAE,CAAA,CAAC,CAAC,CAAA;AAEjE3B,IAAAA,kCAAkC,CAChC2B,IAAI,CAAC,YAAY,CAAC,EAClBA,IAAI,CAAC,aAAa,CAAC,EACnBV,QAAQ,CAACa,KAAK,EACdH,IAAI,CAAC,2BAA2B,CAClC,CAAC,CAAA;AACH,GACF,CAAC,CACAI,IAAI,EAAE,CAACJ,IAAI,CAAA;AAChB;;;;"}
|
|
1
|
+
{"version":3,"file":"cli.mjs","sources":["../zod-config-builder/src//types.ts","../zod-config-builder/src//transformers/removeDisabledSlices.ts","../zod-config-builder/src//utils/transformConfig.ts","../zod-config-builder/src//utils/transformWriteConfig.ts","../zod-config-builder/src//transformers/setupExperiments.ts","../zod-config-builder/src//utils/importValidateTransformWriteConfig.ts","../zod-config-builder/src//cli.ts"],"sourcesContent":["import { type List } from 'ts-toolbelt';\nimport { type Includes, type Join } from 'type-fest';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyRecord = Record<string, any>;\n\nexport type Buckets<Config extends AnyRecord> = Record<string, Experiment<Config>>;\n\nexport interface ConfigParserOptions {\n experimentsCallback?: RunExperimentsCallback;\n}\n\nexport interface Experiment<Config extends AnyRecord> {\n action?: TransformConfigHandlerAction;\n value?: Config;\n}\n\nexport enum NonEmumeralProperties {\n CALLBACKS = '__callbacks',\n DISABLED = '__disabled',\n EXPERIMENT = '__experiment',\n ID = '__id',\n TYPE = '__type',\n ZCB = '__zcb',\n}\n\nexport type Path<Config extends object> = Join<Leaves<Config>, '.'>;\n\nexport type RunExperimentsCallback = (id: string) => Promise<string>;\n\nexport type Scope<Config extends object> = Join<Paths<Config>, '.'>;\n\nexport type SetupExperimentsCallback = <Config extends AnyRecord>(\n id: string,\n clone: Config,\n config: Config\n) => Promise<Buckets<Config>>;\n\nexport type TransformConfigHandler = <Config extends AnyRecord>(\n clone: Config,\n config: Config\n) => TransformConfigHandlerReturnType<Config> | Promise<TransformConfigHandlerReturnType<Config>>;\n\nexport type TransformConfigHandlerSync = <Config extends AnyRecord>(\n clone: Config,\n config: Config\n) => TransformConfigHandlerReturnType<Config>;\n\nexport enum TransformConfigHandlerAction {\n DELETE_NODE = 'deleteNode',\n SKIP_NODE = 'skipNode',\n}\n\nexport interface TransformConfigHandlerReturnType<Config extends AnyRecord> {\n action?: TransformConfigHandlerAction;\n value?: Config;\n}\n\nexport interface WriteConfigOptions {\n experimentsCallback?: SetupExperimentsCallback;\n outputFile: string;\n}\n\nexport type Leaves<T, LeafPath extends string[] = []> = T extends string\n ? LeafPath\n : {\n [K in keyof T & string]: Leaves<T[K], [...LeafPath, K]>;\n }[keyof T & string];\n\nexport type Paths<T, LeafPath extends string[] = []> = T extends string\n ? LeafPath\n : {\n [K in keyof T & string]: T[K] extends object ? Paths<T[K], [...LeafPath, K]> : LeafPath;\n }[keyof T & string];\n\nexport type LeavesScopeDiffs<T1 extends readonly string[][], T2 extends string[]> = {\n [K1 in keyof T1]: List.Length<List.Intersect<T1[K1], T2, '<-contains'>> extends 1\n ? List.Length<T1[K1]> extends 1\n ? Includes<T2, T1[K1][0]> extends false\n ? T1[K1]\n : never\n : List.Diff<T1[K1], T2>\n : never;\n}[number];\n","import {\n type AnyRecord,\n NonEmumeralProperties,\n TransformConfigHandlerAction,\n type TransformConfigHandlerSync,\n} from '../types.ts';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const removeDisabledSlices: TransformConfigHandlerSync = <Config extends AnyRecord>(\n clone: Config,\n config: Config\n) => {\n if (NonEmumeralProperties.DISABLED in config) {\n return {\n action: TransformConfigHandlerAction.DELETE_NODE,\n };\n }\n\n return {\n value: clone,\n };\n};\n","import { castArray, isPlainObject } from 'lodash-es';\nimport {\n type AnyRecord,\n type TransformConfigHandler,\n TransformConfigHandlerAction,\n type TransformConfigHandlerSync,\n} from '../types.ts';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst transformArray = (list: any[], handler: TransformConfigHandler | TransformConfigHandler[]): Promise<any[]> =>\n Promise.all(\n list.map(entry => {\n if (isPlainObject(entry)) {\n return transformConfig(entry, handler);\n }\n\n if (Array.isArray(entry)) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return transformArray(entry, handler);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return entry;\n })\n );\n\nexport const transformConfig = async <Config extends AnyRecord>(\n config: Config,\n handler: TransformConfigHandler | TransformConfigHandler[] = []\n): Promise<Config> => {\n let transform = {} as Config;\n const handlers = castArray(handler);\n\n for (const callback of handlers) {\n const result = await Promise.resolve(callback(transform, config));\n\n if (result.action === TransformConfigHandlerAction.DELETE_NODE) {\n return {} as Config;\n }\n\n if (result.value) {\n transform = result.value;\n }\n\n if (result.action === TransformConfigHandlerAction.SKIP_NODE) {\n return transform;\n }\n }\n\n for (const key in config) {\n const value = config[key];\n\n if (isPlainObject(value)) {\n transform[key] = await transformConfig(value, handler);\n } else if (Array.isArray(value)) {\n transform[key] = (await transformArray(value, handler)) as Config[Extract<keyof Config, string>];\n } else {\n transform[key] = value;\n }\n }\n\n return transform;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst transformArraySync = (list: any[], handler: TransformConfigHandlerSync | TransformConfigHandlerSync[]): any[] =>\n list.map(entry => {\n if (isPlainObject(entry)) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return transformConfigSync(entry, handler);\n }\n\n if (Array.isArray(entry)) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return transformArraySync(entry, handler);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return entry;\n });\n\nexport const transformConfigSync = <Config extends AnyRecord>(\n config: Config,\n handler: TransformConfigHandlerSync | TransformConfigHandlerSync[] = []\n): Config => {\n let transform = {} as Config;\n const handlers = castArray(handler);\n\n for (const callback of handlers) {\n const result = callback(transform, config);\n\n if (result.action === TransformConfigHandlerAction.DELETE_NODE) {\n return {} as Config;\n }\n\n if (result.value) {\n transform = result.value;\n }\n\n if (result.action === TransformConfigHandlerAction.SKIP_NODE) {\n return transform;\n }\n }\n\n for (const key in config) {\n const value = config[key];\n\n if (isPlainObject(value)) {\n transform[key] = transformConfigSync(value, handler);\n } else if (Array.isArray(value)) {\n transform[key] = transformArraySync(value, handler) as Config[Extract<keyof Config, string>];\n } else {\n transform[key] = value;\n }\n }\n\n return transform;\n};\n","import { outputFileSync } from 'fs-extra/esm';\nimport Handlebars from 'handlebars';\nimport { readFileSync } from 'node:fs';\nimport { dirname, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport shelljs from 'shelljs';\nimport { removeDisabledSlices } from '../transformers/removeDisabledSlices.ts';\nimport { setupExperiments } from '../transformers/setupExperiments.ts';\nimport { type TransformConfigHandler, type WriteConfigOptions } from '../types.ts';\nimport { transformConfig } from './transformConfig.ts';\n\nexport const transformWriteConfig = async <Config extends object>(\n config: Config,\n { experimentsCallback, outputFile }: WriteConfigOptions\n) => {\n const handlers: TransformConfigHandler[] = [removeDisabledSlices];\n\n if (experimentsCallback) {\n handlers.push(setupExperiments(experimentsCallback));\n }\n\n const template = Handlebars.compile(\n readFileSync(resolve(dirname(fileURLToPath(import.meta.url)), './templates/config.ts.hbs'), { encoding: 'utf8' })\n );\n\n const output = template({ config: JSON.stringify(await transformConfig(config, handlers), undefined, 2) }).replaceAll(\n /\"([A-Za-z][\\dA-Za-z]+)\":/g,\n '$1:'\n );\n\n shelljs.echo(`zcd watch => writing to file: ${outputFile}`);\n shelljs.echo(`zcd watch => content to write:\\n${output}\\n`);\n outputFileSync(resolve(process.cwd(), outputFile), output);\n};\n","import {\n type AnyRecord,\n NonEmumeralProperties,\n type SetupExperimentsCallback,\n type TransformConfigHandler,\n} from '../types.ts';\n\nexport const setupExperiments =\n (callback: SetupExperimentsCallback): TransformConfigHandler =>\n async <Config extends AnyRecord>(clone: Config, config: Config) => {\n if (NonEmumeralProperties.EXPERIMENT in config && typeof config.__experiment === 'string') {\n const buckets = await callback(config.__experiment, clone, config);\n\n // @ts-expect-error private property\n clone.__experiment = {\n buckets,\n id: config.__experiment,\n };\n\n return {\n value: clone,\n };\n }\n\n return {\n value: clone,\n };\n };\n","import { resolve } from 'node:path';\nimport shelljs from 'shelljs';\nimport { type Commands } from '../cli.ts';\nimport { type ConfigBuilder } from '../createConfigBuilder.ts';\nimport { type SetupExperimentsCallback } from '../types.ts';\nimport { transformWriteConfig } from './transformWriteConfig.ts';\n\nexport const importValidateTransformWriteConfig = (\n inputFile: string,\n outputFile: string,\n command: Commands,\n experimentCallbackFile?: string\n) => {\n import(resolve(process.cwd(), inputFile))\n .then(({ default: configBuilder }: { default: ConfigBuilder<object> }) => {\n if (!configBuilder.$validate()) {\n shelljs.echo(`zcd ${command} => invalid config`);\n shelljs.echo(`zcd ${command} => config values:\\n${configBuilder.$toJson()}\\n`);\n shelljs.echo(`zcd ${command} => errors:\\n${JSON.stringify(configBuilder.$errors(), undefined, 2)}\\n`);\n shelljs.exit(1);\n }\n\n shelljs.echo('zcd ${command} => valid config');\n shelljs.echo(`zcd ${command} => config values:\\n${configBuilder.$toJson()}\\n`);\n\n if (experimentCallbackFile) {\n import(resolve(process.cwd(), experimentCallbackFile))\n .then(({ default: experimentsCallback }: { default: SetupExperimentsCallback }) => {\n void transformWriteConfig(configBuilder.$values(), { experimentsCallback, outputFile });\n })\n .catch((error: unknown) => {\n if (error instanceof Error) {\n shelljs.echo(`zcd ${command} => error message: ${error.message}`);\n\n if (error.stack) {\n shelljs.echo(`zcd ${command} => error stack:\\n${error.stack}\\n`);\n }\n }\n });\n\n return;\n }\n\n void transformWriteConfig(configBuilder.$values(), { outputFile });\n })\n .catch((error: unknown) => {\n if (error instanceof Error) {\n shelljs.echo(`zcd ${command} => error message: ${error.message}`);\n\n if (error.stack) {\n shelljs.echo(`zcd ${command} => error stack:\\n${error.stack}\\n`);\n }\n }\n });\n};\n","import { watchFile } from 'node:fs';\nimport { resolve } from 'node:path';\nimport shelljs from 'shelljs';\nimport yargs from 'yargs';\nimport { importValidateTransformWriteConfig } from './utils/importValidateTransformWriteConfig.ts';\n\nexport enum Commands {\n BUILD = 'build',\n WATCH = 'watch',\n}\n\nconst generateArguments = (cmdYargs: yargs.Argv) =>\n cmdYargs\n .positional('input-file', {\n demandOption: true,\n desc: 'The relative path to the config builder root file',\n type: 'string',\n })\n .positional('output-file', {\n demandOption: true,\n desc: 'The relative path to the output config file',\n type: 'string',\n })\n .option('experiments-callback-file', {\n desc: 'The relative path to the experiment callback file',\n type: 'string',\n });\n\nexport const cli = () => {\n yargs\n .command(\n 'watch <input-file> <output-file>',\n 'Watch a config builder and write config',\n cmdYargs => generateArguments(cmdYargs),\n argv => {\n shelljs.echo(`zcd watch => watching file: ${argv['input-file']}`);\n\n watchFile(resolve(process.cwd(), argv['input-file']), () => {\n shelljs.echo('zcd watch => file change detected');\n\n importValidateTransformWriteConfig(\n argv['input-file'],\n argv['output-file'],\n Commands.WATCH,\n argv['experiments-callback-file']\n );\n });\n }\n )\n .command(\n 'build <input-file> <output-file>',\n 'Write config from a config builder',\n cmdYargs => generateArguments(cmdYargs),\n argv => {\n shelljs.echo(`zcd build => building file: ${argv['input-file']}`);\n\n importValidateTransformWriteConfig(\n argv['input-file'],\n argv['output-file'],\n Commands.BUILD,\n argv['experiments-callback-file']\n );\n }\n )\n .help().argv;\n};\n"],"names":["NonEmumeralProperties","TransformConfigHandlerAction","removeDisabledSlices","clone","config","DISABLED","action","DELETE_NODE","value","transformArray","list","handler","Promise","all","map","entry","isPlainObject","transformConfig","Array","isArray","async","transform","handlers","castArray","callback","result","resolve","SKIP_NODE","key","transformWriteConfig","experimentsCallback","outputFile","push","EXPERIMENT","__experiment","buckets","id","output","Handlebars","compile","readFileSync","dirname","fileURLToPath","url","encoding","template","JSON","stringify","undefined","replaceAll","shelljs","echo","outputFileSync","process","cwd","importValidateTransformWriteConfig","inputFile","command","experimentCallbackFile","import","then","default","configBuilder","$validate","$toJson","$errors","exit","$values","catch","error","Error","message","stack","Commands","generateArguments","cmdYargs","positional","demandOption","desc","type","option","cli","yargs","argv","watchFile","help"],"mappings":"+WAiBYA,SAAAA,2HAAAA,CAAAA,IAAAA,EAAAA,CAAAA,IA+BAC,SAAAA,qDAAAA,CAAAA,IAAAA,EAAAA,CAAAA,ICxCL,MAAMC,EAAmD,CAC9DC,EACAC,IAEIJ,EAAsBK,YAAYD,EAC7B,CACLE,OAAQL,EAA6BM,aAIlC,CACLC,MAAOL,GCVLM,EAAiB,CAACC,EAAaC,IACnCC,QAAQC,IACNH,EAAKI,KAAIC,GACHC,EAAcD,GACTE,EAAgBF,EAAOJ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C,KAAK,+BAA+BgC,EAAK,iBAEjDC,EAAU1D,EAAQ2B,QAAQC,MAAO6B,EAAK,gBAAgB,KACpDjC,EAAQC,KAAK,qCAEbI,EACE4B,EAAK,cACLA,EAAK,eAAc,QAEnBA,EAAK,6BAA4B,GAErC,IAGH1B,QACC,mCACA,sCACAkB,GAAYD,EAAkBC,KAC9BQ,IACEjC,EAAQC,KAAK,+BAA+BgC,EAAK,iBAEjD5B,EACE4B,EAAK,cACLA,EAAK,eAAc,QAEnBA,EAAK,6BAA4B,IAItCE,OAAOF,IAAI"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,373 +1,2 @@
|
|
|
1
|
-
import { isBoolean, isUndefined, isPlainObject, castArray, merge, cloneDeep, get } from 'lodash-es';
|
|
2
|
-
import { v4 } from 'uuid';
|
|
3
|
-
import { zodToJsonSchema } from 'zod-to-json-schema';
|
|
4
|
-
import { ZodType } from 'zod';
|
|
5
|
-
import 'core-js/modules/es.array.push.js';
|
|
6
|
-
|
|
7
|
-
let NonEmumeralProperties = function (NonEmumeralProperties) {
|
|
8
|
-
NonEmumeralProperties["CALLBACKS"] = "__callbacks";
|
|
9
|
-
NonEmumeralProperties["DISABLED"] = "__disabled";
|
|
10
|
-
NonEmumeralProperties["EXPERIMENT"] = "__experiment";
|
|
11
|
-
NonEmumeralProperties["ID"] = "__id";
|
|
12
|
-
NonEmumeralProperties["TYPE"] = "__type";
|
|
13
|
-
NonEmumeralProperties["ZCB"] = "__zcb";
|
|
14
|
-
return NonEmumeralProperties;
|
|
15
|
-
}({});
|
|
16
|
-
let TransformConfigHandlerAction = function (TransformConfigHandlerAction) {
|
|
17
|
-
TransformConfigHandlerAction["DELETE_NODE"] = "deleteNode";
|
|
18
|
-
TransformConfigHandlerAction["SKIP_NODE"] = "skipNode";
|
|
19
|
-
return TransformConfigHandlerAction;
|
|
20
|
-
}({});
|
|
21
|
-
|
|
22
|
-
const NON_ENUMERABLE_KEYS = new Set(Object.values(NonEmumeralProperties));
|
|
23
|
-
const cloneNonEnumerableValues = (clone, config) => {
|
|
24
|
-
for (const nonEnumerableKey of NON_ENUMERABLE_KEYS) {
|
|
25
|
-
if (nonEnumerableKey in config) {
|
|
26
|
-
Object.defineProperty(clone, nonEnumerableKey, {
|
|
27
|
-
configurable: false,
|
|
28
|
-
enumerable: false,
|
|
29
|
-
value: config[nonEnumerableKey]
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return {
|
|
34
|
-
value: clone
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const arrayHasInvalidDefaults = propertyDefinition => {
|
|
39
|
-
const {
|
|
40
|
-
items
|
|
41
|
-
} = propertyDefinition;
|
|
42
|
-
return items && typeof items === 'object' && 'default' in items;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const objectPropertyHasDefaults = propertyDefinition => propertyDefinition.properties && Object.values(propertyDefinition.properties).some(value => typeof value === 'object' && 'default' in value);
|
|
46
|
-
|
|
47
|
-
const collateObjectPropertyDefaults = propertyDefinition => {
|
|
48
|
-
const {
|
|
49
|
-
properties
|
|
50
|
-
} = propertyDefinition;
|
|
51
|
-
if (!properties || !objectPropertyHasDefaults(propertyDefinition)) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
return Object.keys(properties).reduce((acc, key) => {
|
|
55
|
-
const propertyDef = properties[key];
|
|
56
|
-
if (!propertyDef || isBoolean(propertyDef)) {
|
|
57
|
-
return acc;
|
|
58
|
-
}
|
|
59
|
-
if ('default' in propertyDef && !isUndefined(propertyDef.default)) {
|
|
60
|
-
acc[key] = propertyDef.default;
|
|
61
|
-
}
|
|
62
|
-
return acc;
|
|
63
|
-
}, {});
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const RESERVED_KEYWORDS = new Set(['$disable', '$errors', '$experiment', '$extend', '$flush', '$fork', '$toJson', '$validate', '$values']);
|
|
67
|
-
const isPropertyReservedWord = propertyName => RESERVED_KEYWORDS.has(propertyName);
|
|
68
|
-
|
|
69
|
-
const isValidPropertyDefinition = propertyDefinition => typeof propertyDefinition === 'object';
|
|
70
|
-
|
|
71
|
-
const recordHasInvalidDefaults = propertyDefinition => propertyDefinition.additionalProperties && typeof propertyDefinition.additionalProperties === 'object' && 'default' in propertyDefinition.additionalProperties;
|
|
72
|
-
|
|
73
|
-
const collateDefaultValues = jsonSchema => {
|
|
74
|
-
const defaultValues = {};
|
|
75
|
-
for (const propertyName in jsonSchema.properties) {
|
|
76
|
-
if (isPropertyReservedWord(propertyName)) {
|
|
77
|
-
throw new Error(`"${propertyName}" is a reserved keyword within the config builder. Please use a different property name. The full list of reserved keywords is: ${[...RESERVED_KEYWORDS].join(', ')}`);
|
|
78
|
-
}
|
|
79
|
-
const castPropertyName = propertyName;
|
|
80
|
-
const propertyDefinition = jsonSchema.properties[propertyName];
|
|
81
|
-
if (isValidPropertyDefinition(propertyDefinition)) {
|
|
82
|
-
if (propertyDefinition.default) {
|
|
83
|
-
defaultValues[castPropertyName] = propertyDefinition.default;
|
|
84
|
-
}
|
|
85
|
-
if (propertyDefinition.type === 'array' && arrayHasInvalidDefaults(propertyDefinition)) {
|
|
86
|
-
throw new Error(`When setting schema array defaults for the array assigned to "${String(castPropertyName)}", set them on the array and not the item.`);
|
|
87
|
-
}
|
|
88
|
-
if (propertyDefinition.type === 'object') {
|
|
89
|
-
if (recordHasInvalidDefaults(propertyDefinition)) {
|
|
90
|
-
throw new Error(`When setting schema property defaults for the value of the record assigned to "${String(castPropertyName)}", set them on the record and not the value.`);
|
|
91
|
-
}
|
|
92
|
-
const propertyDefaults = collateObjectPropertyDefaults(propertyDefinition);
|
|
93
|
-
if (propertyDefaults) {
|
|
94
|
-
defaultValues[castPropertyName] = propertyDefaults;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return defaultValues;
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
const isDerivedValueCallback = value => typeof value === 'function';
|
|
103
|
-
|
|
104
|
-
const isInvalidPropertyOverride = (propertyValue, override = false) => !override && propertyValue !== undefined;
|
|
105
|
-
|
|
106
|
-
const isSchemaValid = schema => schema.type !== 'object';
|
|
107
|
-
|
|
108
|
-
const isValidValue = (value, depth = 0) => {
|
|
109
|
-
if (isPlainObject(value)) {
|
|
110
|
-
const object = value;
|
|
111
|
-
if (object.__zcb === true) {
|
|
112
|
-
return true;
|
|
113
|
-
}
|
|
114
|
-
if (depth < 1 && Object.values(object).every(v => isValidValue(v, depth + 1))) {
|
|
115
|
-
return true;
|
|
116
|
-
}
|
|
117
|
-
return false;
|
|
118
|
-
}
|
|
119
|
-
if (Array.isArray(value)) {
|
|
120
|
-
if (value.every(v => isValidValue(v, depth + 1))) {
|
|
121
|
-
return true;
|
|
122
|
-
}
|
|
123
|
-
return false;
|
|
124
|
-
}
|
|
125
|
-
return true;
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
const jsonStringifyReplacer = (_key, value) => value instanceof ZodType ? zodToJsonSchema(value, {
|
|
129
|
-
errorMessages: true
|
|
130
|
-
}) : value;
|
|
131
|
-
|
|
132
|
-
const transformArray = (list, handler) => Promise.all(list.map(entry => {
|
|
133
|
-
if (isPlainObject(entry)) {
|
|
134
|
-
return transformConfig(entry, handler);
|
|
135
|
-
}
|
|
136
|
-
if (Array.isArray(entry)) {
|
|
137
|
-
return transformArray(entry, handler);
|
|
138
|
-
}
|
|
139
|
-
return entry;
|
|
140
|
-
}));
|
|
141
|
-
const transformConfig = async (config, handler = []) => {
|
|
142
|
-
let transform = {};
|
|
143
|
-
const handlers = castArray(handler);
|
|
144
|
-
for (const callback of handlers) {
|
|
145
|
-
const result = await Promise.resolve(callback(transform, config));
|
|
146
|
-
if (result.action === TransformConfigHandlerAction.DELETE_NODE) {
|
|
147
|
-
return {};
|
|
148
|
-
}
|
|
149
|
-
if (result.value) {
|
|
150
|
-
transform = result.value;
|
|
151
|
-
}
|
|
152
|
-
if (result.action === TransformConfigHandlerAction.SKIP_NODE) {
|
|
153
|
-
return transform;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
for (const key in config) {
|
|
157
|
-
const value = config[key];
|
|
158
|
-
if (isPlainObject(value)) {
|
|
159
|
-
transform[key] = await transformConfig(value, handler);
|
|
160
|
-
} else if (Array.isArray(value)) {
|
|
161
|
-
transform[key] = await transformArray(value, handler);
|
|
162
|
-
} else {
|
|
163
|
-
transform[key] = value;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
return transform;
|
|
167
|
-
};
|
|
168
|
-
const transformArraySync = (list, handler) => list.map(entry => {
|
|
169
|
-
if (isPlainObject(entry)) {
|
|
170
|
-
return transformConfigSync(entry, handler);
|
|
171
|
-
}
|
|
172
|
-
if (Array.isArray(entry)) {
|
|
173
|
-
return transformArraySync(entry, handler);
|
|
174
|
-
}
|
|
175
|
-
return entry;
|
|
176
|
-
});
|
|
177
|
-
const transformConfigSync = (config, handler = []) => {
|
|
178
|
-
let transform = {};
|
|
179
|
-
const handlers = castArray(handler);
|
|
180
|
-
for (const callback of handlers) {
|
|
181
|
-
const result = callback(transform, config);
|
|
182
|
-
if (result.action === TransformConfigHandlerAction.DELETE_NODE) {
|
|
183
|
-
return {};
|
|
184
|
-
}
|
|
185
|
-
if (result.value) {
|
|
186
|
-
transform = result.value;
|
|
187
|
-
}
|
|
188
|
-
if (result.action === TransformConfigHandlerAction.SKIP_NODE) {
|
|
189
|
-
return transform;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
for (const key in config) {
|
|
193
|
-
const value = config[key];
|
|
194
|
-
if (isPlainObject(value)) {
|
|
195
|
-
transform[key] = transformConfigSync(value, handler);
|
|
196
|
-
} else if (Array.isArray(value)) {
|
|
197
|
-
transform[key] = transformArraySync(value, handler);
|
|
198
|
-
} else {
|
|
199
|
-
transform[key] = value;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
return transform;
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
const createConfigBuilder = (zodSchema, options = {}, derivedValueCallbacks = {}, initialValues = {}) => {
|
|
206
|
-
const jsonSchema = zodToJsonSchema(zodSchema);
|
|
207
|
-
if (isSchemaValid(jsonSchema)) {
|
|
208
|
-
throw new Error(`The root type of a config schema must be "object", but received "${String(jsonSchema.type)}"`);
|
|
209
|
-
}
|
|
210
|
-
const uuid = options.overrides?.uuid ?? v4;
|
|
211
|
-
const addNonEnumeralBaseProperties = conf => {
|
|
212
|
-
Object.defineProperty(conf, NonEmumeralProperties.ZCB, {
|
|
213
|
-
configurable: false,
|
|
214
|
-
enumerable: false,
|
|
215
|
-
value: true
|
|
216
|
-
});
|
|
217
|
-
Object.defineProperty(conf, NonEmumeralProperties.ID, {
|
|
218
|
-
configurable: false,
|
|
219
|
-
enumerable: false,
|
|
220
|
-
value: uuid()
|
|
221
|
-
});
|
|
222
|
-
if (options.type) {
|
|
223
|
-
Object.defineProperty(conf, NonEmumeralProperties.TYPE, {
|
|
224
|
-
configurable: false,
|
|
225
|
-
enumerable: false,
|
|
226
|
-
value: options.type
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
const createInitialConfig = () => {
|
|
231
|
-
const config = merge(cloneDeep(initialValues), collateDefaultValues(jsonSchema));
|
|
232
|
-
addNonEnumeralBaseProperties(config);
|
|
233
|
-
return config;
|
|
234
|
-
};
|
|
235
|
-
let config = createInitialConfig();
|
|
236
|
-
let callbacks = {
|
|
237
|
-
...derivedValueCallbacks
|
|
238
|
-
};
|
|
239
|
-
const configBuilder = {
|
|
240
|
-
$disable: () => {
|
|
241
|
-
Object.defineProperty(config, NonEmumeralProperties.DISABLED, {
|
|
242
|
-
configurable: false,
|
|
243
|
-
enumerable: false,
|
|
244
|
-
value: true
|
|
245
|
-
});
|
|
246
|
-
return configBuilder;
|
|
247
|
-
},
|
|
248
|
-
$errors: () => {
|
|
249
|
-
try {
|
|
250
|
-
zodSchema.parse(configBuilder.$values());
|
|
251
|
-
return [];
|
|
252
|
-
} catch (error) {
|
|
253
|
-
return error.errors;
|
|
254
|
-
}
|
|
255
|
-
},
|
|
256
|
-
$experiment: key => {
|
|
257
|
-
Object.defineProperty(config, NonEmumeralProperties.EXPERIMENT, {
|
|
258
|
-
configurable: false,
|
|
259
|
-
enumerable: false,
|
|
260
|
-
value: key
|
|
261
|
-
});
|
|
262
|
-
return configBuilder;
|
|
263
|
-
},
|
|
264
|
-
$extend: builder => {
|
|
265
|
-
config = transformConfigSync(builder.$values(), [cloneNonEnumerableValues]);
|
|
266
|
-
callbacks = {
|
|
267
|
-
...builder.__callbacks
|
|
268
|
-
};
|
|
269
|
-
},
|
|
270
|
-
$flush: () => {
|
|
271
|
-
const values = configBuilder.$values();
|
|
272
|
-
config = createInitialConfig();
|
|
273
|
-
return values;
|
|
274
|
-
},
|
|
275
|
-
$fork: () => createConfigBuilder(zodSchema, options, derivedValueCallbacks, initialValues),
|
|
276
|
-
$toJson: () => JSON.stringify(configBuilder.$values(), jsonStringifyReplacer, 2),
|
|
277
|
-
$validate: () => {
|
|
278
|
-
try {
|
|
279
|
-
zodSchema.parse(configBuilder.$values());
|
|
280
|
-
return true;
|
|
281
|
-
} catch (error) {
|
|
282
|
-
console.error(error);
|
|
283
|
-
return false;
|
|
284
|
-
}
|
|
285
|
-
},
|
|
286
|
-
$values: () => {
|
|
287
|
-
for (const property in callbacks) {
|
|
288
|
-
const callback = callbacks[property];
|
|
289
|
-
if (callback) {
|
|
290
|
-
config[property] = callback(config);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
return config;
|
|
294
|
-
}
|
|
295
|
-
};
|
|
296
|
-
Object.defineProperty(configBuilder, NonEmumeralProperties.CALLBACKS, {
|
|
297
|
-
configurable: false,
|
|
298
|
-
enumerable: false,
|
|
299
|
-
value: callbacks
|
|
300
|
-
});
|
|
301
|
-
for (const propertyName in jsonSchema.properties) {
|
|
302
|
-
if (isPropertyReservedWord(propertyName)) {
|
|
303
|
-
throw new Error(`"${propertyName}" is a reserved keyword within the config builder. Please use a different property name. The full list of reserved keywords is: ${[...RESERVED_KEYWORDS].join(', ')}`);
|
|
304
|
-
}
|
|
305
|
-
const castPropertyName = propertyName;
|
|
306
|
-
configBuilder[castPropertyName] = (value, override) => {
|
|
307
|
-
if (isInvalidPropertyOverride(config[castPropertyName], override)) {
|
|
308
|
-
throw new Error(`A value already exists for "${String(castPropertyName)}". You may be trying to add a new values before flushing the old one. If you intended to override the existing value, pass in true as the second argument.`);
|
|
309
|
-
}
|
|
310
|
-
let propertyValue;
|
|
311
|
-
const MAX_DEPTH = 1;
|
|
312
|
-
if (!isValidValue(value)) {
|
|
313
|
-
throw new Error(`"${String(castPropertyName)}" value has a depth greater than ${MAX_DEPTH}. To pass in objects with a depth greater than ${MAX_DEPTH}, create a builder for that config slice.`);
|
|
314
|
-
}
|
|
315
|
-
if (isDerivedValueCallback(value)) {
|
|
316
|
-
callbacks[castPropertyName] = value;
|
|
317
|
-
propertyValue = value(config);
|
|
318
|
-
} else {
|
|
319
|
-
propertyValue = value;
|
|
320
|
-
}
|
|
321
|
-
config[castPropertyName] = propertyValue;
|
|
322
|
-
return configBuilder;
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
return configBuilder;
|
|
326
|
-
};
|
|
327
|
-
|
|
328
|
-
const runExperiments = callback => async (clone, config) => {
|
|
329
|
-
if (NonEmumeralProperties.EXPERIMENT in config && typeof config.__experiment === 'object') {
|
|
330
|
-
const {
|
|
331
|
-
buckets,
|
|
332
|
-
id
|
|
333
|
-
} = config.__experiment;
|
|
334
|
-
const bucket = await callback(id);
|
|
335
|
-
if (bucket && bucket in buckets && buckets[bucket]) {
|
|
336
|
-
return buckets[bucket];
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
return {
|
|
340
|
-
value: clone
|
|
341
|
-
};
|
|
342
|
-
};
|
|
343
|
-
|
|
344
|
-
const createConfigParser = async (config, {
|
|
345
|
-
experimentsCallback
|
|
346
|
-
} = {}) => {
|
|
347
|
-
const handlers = [];
|
|
348
|
-
if (experimentsCallback) {
|
|
349
|
-
handlers.push(runExperiments(experimentsCallback));
|
|
350
|
-
}
|
|
351
|
-
return handlers.length > 0 ? await transformConfig(config, handlers) : config;
|
|
352
|
-
};
|
|
353
|
-
|
|
354
|
-
const createConfigReader = config => {
|
|
355
|
-
const configReader = {
|
|
356
|
-
read: path => get(config, path),
|
|
357
|
-
scope: scope => createConfigReader(get(config, scope))
|
|
358
|
-
};
|
|
359
|
-
return configReader;
|
|
360
|
-
};
|
|
361
|
-
|
|
362
|
-
const countryCodes = ['AF', 'AX', 'AL', 'DZ', 'AS', 'AD', 'AO', 'AI', 'AQ', 'AG', 'AR', 'AM', 'AW', 'AU', 'AT', 'AZ', 'BS', 'BH', 'BD', 'BB', 'BY', 'BE', 'BZ', 'BJ', 'BM', 'BT', 'BO', 'BA', 'BW', 'BV', 'BR', 'IO', 'BN', 'BG', 'BF', 'BI', 'KH', 'CM', 'CA', 'CV', 'KY', 'CF', 'TD', 'CL', 'CN', 'CX', 'CC', 'CO', 'KM', 'CG', 'CD', 'CK', 'CR', 'CI', 'HR', 'CU', 'CY', 'CZ', 'DK', 'DJ', 'DM', 'DO', 'EC', 'EG', 'SV', 'GQ', 'ER', 'EE', 'ET', 'FK', 'FO', 'FJ', 'FI', 'FR', 'GF', 'PF', 'TF', 'GA', 'GM', 'GE', 'DE', 'GH', 'GI', 'GR', 'GL', 'GD', 'GP', 'GU', 'GT', 'GG', 'GN', 'GW', 'GY', 'HT', 'HM', 'VA', 'HN', 'HK', 'HU', 'IS', 'IN', 'ID', 'IR', 'IQ', 'IE', 'IM', 'IL', 'IT', 'JM', 'JP', 'JE', 'JO', 'KZ', 'KE', 'KI', 'KR', 'KW', 'KG', 'LA', 'LV', 'LB', 'LS', 'LR', 'LY', 'LI', 'LT', 'LU', 'MO', 'MK', 'MG', 'MW', 'MY', 'MV', 'ML', 'MT', 'MH', 'MQ', 'MR', 'MU', 'YT', 'MX', 'FM', 'MD', 'MC', 'MN', 'ME', 'MS', 'MA', 'MZ', 'MM', 'NA', 'NR', 'NP', 'NL', 'AN', 'NC', 'NZ', 'NI', 'NE', 'NG', 'NU', 'NF', 'MP', 'NO', 'OM', 'PK', 'PW', 'PS', 'PA', 'PG', 'PY', 'PE', 'PH', 'PN', 'PL', 'PT', 'PR', 'QA', 'RE', 'RO', 'RU', 'RW', 'BL', 'SH', 'KN', 'LC', 'MF', 'PM', 'VC', 'WS', 'SM', 'ST', 'SA', 'SN', 'RS', 'SC', 'SL', 'SG', 'SK', 'SI', 'SB', 'SO', 'ZA', 'GS', 'ES', 'LK', 'SD', 'SR', 'SJ', 'SZ', 'SE', 'CH', 'SY', 'TW', 'TJ', 'TZ', 'TH', 'TL', 'TG', 'TK', 'TO', 'TT', 'TN', 'TR', 'TM', 'TC', 'TV', 'UG', 'UA', 'AE', 'GB', 'US', 'UM', 'UY', 'UZ', 'VU', 'VE', 'VN', 'VG', 'VI', 'WF', 'EH', 'YE', 'ZM', 'ZW'];
|
|
363
|
-
|
|
364
|
-
const countryNames = ['Afghanistan', 'Albania', 'Algeria', 'Andorra', 'Angola', 'Anguilla', 'Antigua and Barbuda', 'Argentina', 'Armenia', 'Aruba', 'Australia', 'Austria', 'Azerbaijan', 'Bahamas', 'Bahrain', 'Bangladesh', 'Barbados', 'Belarus', 'Belgium', 'Belize', 'Benin', 'Bermuda', 'Bhutan', 'Bolivia', 'Bosnia and Herzegovina', 'Botswana', 'Brazil', 'British Virgin Islands', 'Brunei', 'Bulgaria', 'Burkina Faso', 'Burundi', 'Cambodia', 'Cameroon', 'Cape Verde', 'Cayman Islands', 'Chad', 'Chile', 'China', 'Colombia', 'Congo', 'Cook Islands', 'Costa Rica', 'Cote D Ivoire', 'Croatia', 'Cruise Ship', 'Cuba', 'Cyprus', 'Czech Republic', 'Denmark', 'Djibouti', 'Dominica', 'Dominican Republic', 'Ecuador', 'Egypt', 'El Salvador', 'Equatorial Guinea', 'Estonia', 'Ethiopia', 'Falkland Islands', 'Faroe Islands', 'Fiji', 'Finland', 'France', 'French Polynesia', 'French West Indies', 'Gabon', 'Gambia', 'Georgia', 'Germany', 'Ghana', 'Gibraltar', 'Greece', 'Greenland', 'Grenada', 'Guam', 'Guatemala', 'Guernsey', 'Guinea', 'Guinea Bissau', 'Guyana', 'Haiti', 'Honduras', 'Hong Kong', 'Hungary', 'Iceland', 'India', 'Indonesia', 'Iran', 'Iraq', 'Ireland', 'Isle of Man', 'Israel', 'Italy', 'Jamaica', 'Japan', 'Jersey', 'Jordan', 'Kazakhstan', 'Kenya', 'Kuwait', 'Kyrgyz Republic', 'Laos', 'Latvia', 'Lebanon', 'Lesotho', 'Liberia', 'Libya', 'Liechtenstein', 'Lithuania', 'Luxembourg', 'Macau', 'Macedonia', 'Madagascar', 'Malawi', 'Malaysia', 'Maldives', 'Mali', 'Malta', 'Mauritania', 'Mauritius', 'Mexico', 'Moldova', 'Monaco', 'Mongolia', 'Montenegro', 'Montserrat', 'Morocco', 'Mozambique', 'Namibia', 'Nepal', 'Netherlands', 'Netherlands Antilles', 'New Caledonia', 'New Zealand', 'Nicaragua', 'Niger', 'Nigeria', 'Norway', 'Oman', 'Pakistan', 'Palestine', 'Panama', 'Papua New Guinea', 'Paraguay', 'Peru', 'Philippines', 'Poland', 'Portugal', 'Puerto Rico', 'Qatar', 'Reunion', 'Romania', 'Russia', 'Rwanda', 'Saint Pierre and Miquelon', 'Samoa', 'San Marino', 'Satellite', 'Saudi Arabia', 'Senegal', 'Serbia', 'Seychelles', 'Sierra Leone', 'Singapore', 'Slovakia', 'Slovenia', 'South Africa', 'South Korea', 'Spain', 'Sri Lanka', 'St Kitts and Nevis', 'St Lucia', 'St Vincent', 'St. Lucia', 'Sudan', 'Suriname', 'Swaziland', 'Sweden', 'Switzerland', 'Syria', 'Taiwan', 'Tajikistan', 'Tanzania', 'Thailand', "Timor L'Este", 'Togo', 'Tonga', 'Trinidad and Tobago', 'Tunisia', 'Turkey', 'Turkmenistan', 'Turks and Caicos', 'Uganda', 'Ukraine', 'United Arab Emirates', 'United Kingdom', 'Uruguay', 'Uzbekistan', 'Venezuela', 'Vietnam', 'Virgin Islands (US)', 'Yemen', 'Zambia', 'Zimbabwe'];
|
|
365
|
-
|
|
366
|
-
const distanceUnits = ['km', 'mi'];
|
|
367
|
-
|
|
368
|
-
const languageCodes = ['aa', 'ab', 'ae', 'af', 'ak', 'am', 'an', 'ar', 'as', 'av', 'ay', 'az', 'ba', 'be', 'bg', 'bi', 'bm', 'bn', 'bo', 'br', 'bs', 'ca', 'ce', 'ch', 'co', 'cr', 'cs', 'cu', 'cv', 'cy', 'da', 'de', 'dv', 'dz', 'ee', 'el', 'en', 'eo', 'es', 'et', 'eu', 'fa', 'ff', 'fi', 'fj', 'fo', 'fr', 'fy', 'ga', 'gd', 'gl', 'gn', 'gu', 'gv', 'ha', 'he', 'hi', 'ho', 'hr', 'ht', 'hu', 'hy', 'hz', 'ia', 'id', 'ie', 'ig', 'ii', 'ik', 'io', 'is', 'it', 'iu', 'ja', 'jv', 'ka', 'kg', 'ki', 'kj', 'kk', 'kl', 'km', 'kn', 'ko', 'kr', 'ks', 'ku', 'kv', 'kw', 'ky', 'la', 'lb', 'lg', 'li', 'ln', 'lo', 'lt', 'lu', 'lv', 'mg', 'mh', 'mi', 'mk', 'ml', 'mn', 'mr', 'ms', 'mt', 'my', 'na', 'nb', 'nd', 'ne', 'ng', 'nl', 'nn', 'no', 'nr', 'nv', 'ny', 'oc', 'oj', 'om', 'or', 'os', 'pa', 'pi', 'pl', 'ps', 'pt', 'qu', 'rm', 'rn', 'ro', 'ru', 'rw', 'sa', 'sc', 'sd', 'se', 'sg', 'si', 'sk', 'sl', 'sm', 'sn', 'so', 'sq', 'sr', 'ss', 'st', 'su', 'sv', 'sw', 'ta', 'te', 'tg', 'th', 'ti', 'tk', 'tl', 'tn', 'to', 'tr', 'ts', 'tt', 'tw', 'ty', 'ug', 'uk', 'ur', 'uz', 've', 'vi', 'vo', 'wa', 'wo', 'xh', 'yi', 'yo', 'za', 'zh', 'zu'];
|
|
369
|
-
|
|
370
|
-
const timezones = ['Africa/Abidjan', 'Africa/Accra', 'Africa/Addis_Ababa', 'Africa/Algiers', 'Africa/Asmara', 'Africa/Bamako', 'Africa/Bangui', 'Africa/Banjul', 'Africa/Bissau', 'Africa/Blantyre', 'Africa/Brazzaville', 'Africa/Bujumbura', 'Africa/Cairo', 'Africa/Casablanca', 'Africa/Ceuta', 'Africa/Conakry', 'Africa/Dakar', 'Africa/Dar_es_Salaam', 'Africa/Djibouti', 'Africa/Douala', 'Africa/El_Aaiun', 'Africa/Freetown', 'Africa/Gaborone', 'Africa/Harare', 'Africa/Johannesburg', 'Africa/Juba', 'Africa/Kampala', 'Africa/Khartoum', 'Africa/Kigali', 'Africa/Kinshasa', 'Africa/Lagos', 'Africa/Libreville', 'Africa/Lome', 'Africa/Luanda', 'Africa/Lubumbashi', 'Africa/Lusaka', 'Africa/Malabo', 'Africa/Maputo', 'Africa/Maseru', 'Africa/Mbabane', 'Africa/Mogadishu', 'Africa/Monrovia', 'Africa/Nairobi', 'Africa/Ndjamena', 'Africa/Niamey', 'Africa/Nouakchott', 'Africa/Ouagadougou', 'Africa/Porto-Novo', 'Africa/Sao_Tome', 'Africa/Tripoli', 'Africa/Tunis', 'Africa/Windhoek', 'America/Adak', 'America/Anchorage', 'America/Anguilla', 'America/Antigua', 'America/Araguaina', 'America/Argentina/Buenos_Aires', 'America/Argentina/Catamarca', 'America/Argentina/Cordoba', 'America/Argentina/Jujuy', 'America/Argentina/La_Rioja', 'America/Argentina/Mendoza', 'America/Argentina/Rio_Gallegos', 'America/Argentina/Salta', 'America/Argentina/San_Juan', 'America/Argentina/San_Luis', 'America/Argentina/Tucuman', 'America/Argentina/Ushuaia', 'America/Aruba', 'America/Asuncion', 'America/Atikokan', 'America/Bahia', 'America/Bahia_Banderas', 'America/Barbados', 'America/Belem', 'America/Belize', 'America/Blanc-Sablon', 'America/Boa_Vista', 'America/Bogota', 'America/Boise', 'America/Cambridge_Bay', 'America/Campo_Grande', 'America/Cancun', 'America/Caracas', 'America/Cayenne', 'America/Cayman', 'America/Chicago', 'America/Chihuahua', 'America/Costa_Rica', 'America/Creston', 'America/Cuiaba', 'America/Curacao', 'America/Danmarkshavn', 'America/Dawson', 'America/Dawson_Creek', 'America/Denver', 'America/Detroit', 'America/Dominica', 'America/Edmonton', 'America/Eirunepe', 'America/El_Salvador', 'America/Fort_Nelson', 'America/Fortaleza', 'America/Glace_Bay', 'America/Godthab', 'America/Goose_Bay', 'America/Grand_Turk', 'America/Grenada', 'America/Guadeloupe', 'America/Guatemala', 'America/Guayaquil', 'America/Guyana', 'America/Halifax', 'America/Havana', 'America/Hermosillo', 'America/Indiana/Indianapolis', 'America/Indiana/Knox', 'America/Indiana/Marengo', 'America/Indiana/Petersburg', 'America/Indiana/Tell_City', 'America/Indiana/Vevay', 'America/Indiana/Vincennes', 'America/Indiana/Winamac', 'America/Inuvik', 'America/Iqaluit', 'America/Jamaica', 'America/Juneau', 'America/Kentucky/Louisville', 'America/Kentucky/Monticello', 'America/Kralendijk', 'America/La_Paz', 'America/Lima', 'America/Los_Angeles', 'America/Lower_Princes', 'America/Maceio', 'America/Managua', 'America/Manaus', 'America/Marigot', 'America/Martinique', 'America/Matamoros', 'America/Mazatlan', 'America/Menominee', 'America/Merida', 'America/Metlakatla', 'America/Mexico_City', 'America/Miquelon', 'America/Moncton', 'America/Monterrey', 'America/Montevideo', 'America/Montserrat', 'America/Nassau', 'America/New_York', 'America/Nipigon', 'America/Nome', 'America/Noronha', 'America/North_Dakota/Beulah', 'America/North_Dakota/Center', 'America/North_Dakota/New_Salem', 'America/Ojinaga', 'America/Panama', 'America/Pangnirtung', 'America/Paramaribo', 'America/Phoenix', 'America/Port-au-Prince', 'America/Port_of_Spain', 'America/Porto_Velho', 'America/Puerto_Rico', 'America/Rainy_River', 'America/Rankin_Inlet', 'America/Recife', 'America/Regina', 'America/Resolute', 'America/Rio_Branco', 'America/Santa_Isabel', 'America/Santarem', 'America/Santiago', 'America/Santo_Domingo', 'America/Sao_Paulo', 'America/Scoresbysund', 'America/Sitka', 'America/St_Barthelemy', 'America/St_Johns', 'America/St_Kitts', 'America/St_Lucia', 'America/St_Thomas', 'America/St_Vincent', 'America/Swift_Current', 'America/Tegucigalpa', 'America/Thule', 'America/Thunder_Bay', 'America/Tijuana', 'America/Toronto', 'America/Tortola', 'America/Vancouver', 'America/Whitehorse', 'America/Winnipeg', 'America/Yakutat', 'America/Yellowknife', 'Antarctica/Casey', 'Antarctica/Davis', 'Antarctica/DumontDUrville', 'Antarctica/Macquarie', 'Antarctica/Mawson', 'Antarctica/McMurdo', 'Antarctica/Palmer', 'Antarctica/Rothera', 'Antarctica/Syowa', 'Antarctica/Troll', 'Antarctica/Vostok', 'Arctic/Longyearbyen', 'Asia/Aden', 'Asia/Almaty', 'Asia/Amman', 'Asia/Anadyr', 'Asia/Aqtau', 'Asia/Aqtobe', 'Asia/Ashgabat', 'Asia/Baghdad', 'Asia/Bahrain', 'Asia/Baku', 'Asia/Bangkok', 'Asia/Beirut', 'Asia/Bishkek', 'Asia/Brunei', 'Asia/Chita', 'Asia/Choibalsan', 'Asia/Colombo', 'Asia/Damascus', 'Asia/Dhaka', 'Asia/Dili', 'Asia/Dubai', 'Asia/Dushanbe', 'Asia/Gaza', 'Asia/Hebron', 'Asia/Ho_Chi_Minh', 'Asia/Hong_Kong', 'Asia/Hovd', 'Asia/Irkutsk', 'Asia/Jakarta', 'Asia/Jayapura', 'Asia/Jerusalem', 'Asia/Kabul', 'Asia/Kamchatka', 'Asia/Karachi', 'Asia/Kathmandu', 'Asia/Khandyga', 'Asia/Kolkata', 'Asia/Krasnoyarsk', 'Asia/Kuala_Lumpur', 'Asia/Kuching', 'Asia/Kuwait', 'Asia/Macau', 'Asia/Magadan', 'Asia/Makassar', 'Asia/Manila', 'Asia/Muscat', 'Asia/Nicosia', 'Asia/Novokuznetsk', 'Asia/Novosibirsk', 'Asia/Omsk', 'Asia/Oral', 'Asia/Phnom_Penh', 'Asia/Pontianak', 'Asia/Pyongyang', 'Asia/Qatar', 'Asia/Qyzylorda', 'Asia/Rangoon', 'Asia/Riyadh', 'Asia/Sakhalin', 'Asia/Samarkand', 'Asia/Seoul', 'Asia/Shanghai', 'Asia/Singapore', 'Asia/Srednekolymsk', 'Asia/Taipei', 'Asia/Tashkent', 'Asia/Tbilisi', 'Asia/Tehran', 'Asia/Thimphu', 'Asia/Tokyo', 'Asia/Ulaanbaatar', 'Asia/Urumqi', 'Asia/Ust-Nera', 'Asia/Vientiane', 'Asia/Vladivostok', 'Asia/Yakutsk', 'Asia/Yekaterinburg', 'Asia/Yerevan', 'Atlantic/Azores', 'Atlantic/Bermuda', 'Atlantic/Canary', 'Atlantic/Cape_Verde', 'Atlantic/Faroe', 'Atlantic/Madeira', 'Atlantic/Reykjavik', 'Atlantic/South_Georgia', 'Atlantic/St_Helena', 'Atlantic/Stanley', 'Australia/Adelaide', 'Australia/Brisbane', 'Australia/Broken_Hill', 'Australia/Currie', 'Australia/Darwin', 'Australia/Eucla', 'Australia/Hobart', 'Australia/Lindeman', 'Australia/Lord_Howe', 'Australia/Melbourne', 'Australia/Perth', 'Australia/Sydney', 'Europe/Amsterdam', 'Europe/Andorra', 'Europe/Athens', 'Europe/Belgrade', 'Europe/Berlin', 'Europe/Bratislava', 'Europe/Brussels', 'Europe/Bucharest', 'Europe/Budapest', 'Europe/Busingen', 'Europe/Chisinau', 'Europe/Copenhagen', 'Europe/Dublin', 'Europe/Gibraltar', 'Europe/Guernsey', 'Europe/Helsinki', 'Europe/Isle_of_Man', 'Europe/Istanbul', 'Europe/Jersey', 'Europe/Kaliningrad', 'Europe/Kiev', 'Europe/Lisbon', 'Europe/Ljubljana', 'Europe/London', 'Europe/Luxembourg', 'Europe/Madrid', 'Europe/Malta', 'Europe/Mariehamn', 'Europe/Minsk', 'Europe/Monaco', 'Europe/Moscow', 'Europe/Oslo', 'Europe/Paris', 'Europe/Podgorica', 'Europe/Prague', 'Europe/Riga', 'Europe/Rome', 'Europe/Samara', 'Europe/San_Marino', 'Europe/Sarajevo', 'Europe/Simferopol', 'Europe/Skopje', 'Europe/Sofia', 'Europe/Stockholm', 'Europe/Tallinn', 'Europe/Tirane', 'Europe/Uzhgorod', 'Europe/Vaduz', 'Europe/Vatican', 'Europe/Vienna', 'Europe/Vilnius', 'Europe/Volgograd', 'Europe/Warsaw', 'Europe/Zagreb', 'Europe/Zaporozhye', 'Europe/Zurich', 'Indian/Antananarivo', 'Indian/Chagos', 'Indian/Christmas', 'Indian/Cocos', 'Indian/Comoro', 'Indian/Kerguelen', 'Indian/Mahe', 'Indian/Maldives', 'Indian/Mauritius', 'Indian/Mayotte', 'Indian/Reunion', 'Pacific/Apia', 'Pacific/Auckland', 'Pacific/Bougainville', 'Pacific/Chatham', 'Pacific/Chuuk', 'Pacific/Easter', 'Pacific/Efate', 'Pacific/Enderbury', 'Pacific/Fakaofo', 'Pacific/Fiji', 'Pacific/Funafuti', 'Pacific/Galapagos', 'Pacific/Gambier', 'Pacific/Guadalcanal', 'Pacific/Guam', 'Pacific/Honolulu', 'Pacific/Johnston', 'Pacific/Kiritimati', 'Pacific/Kosrae', 'Pacific/Kwajalein', 'Pacific/Majuro', 'Pacific/Marquesas', 'Pacific/Midway', 'Pacific/Nauru', 'Pacific/Niue', 'Pacific/Norfolk', 'Pacific/Noumea', 'Pacific/Pago_Pago', 'Pacific/Palau', 'Pacific/Pitcairn', 'Pacific/Pohnpei', 'Pacific/Port_Moresby', 'Pacific/Rarotonga', 'Pacific/Saipan', 'Pacific/Tahiti', 'Pacific/Tarawa', 'Pacific/Tongatapu', 'Pacific/Wake', 'Pacific/Wallis'];
|
|
371
|
-
|
|
372
|
-
export { NonEmumeralProperties, TransformConfigHandlerAction, cloneNonEnumerableValues, countryCodes, countryNames, createConfigBuilder, createConfigParser, createConfigReader, distanceUnits, languageCodes, timezones };
|
|
1
|
+
import{isBoolean as a,isUndefined as i,isPlainObject as e,castArray as r,merge as n,cloneDeep as o,get as t,isString as c}from"lodash-es";import{v4 as s}from"uuid";import{zodToJsonSchema as A}from"zod-to-json-schema";import{ZodType as u}from"zod";import"core-js/modules/es.array.push.js";var l,m;!function(a){a.CALLBACKS="__callbacks",a.DISABLED="__disabled",a.EXPERIMENT="__experiment",a.ID="__id",a.TYPE="__type",a.ZCB="__zcb"}(l||(l={})),function(a){a.DELETE_NODE="deleteNode",a.SKIP_NODE="skipNode"}(m||(m={}));const d=new Set(Object.values(l)),f=(a,i)=>{for(const e of d)e in i&&Object.defineProperty(a,e,{configurable:!1,enumerable:!1,value:i[e]});return{value:a}},p=a=>{const{items:i}=a;return i&&"object"==typeof i&&"default"in i},h=e=>{const{properties:r}=e;if(r&&(a=>a.properties&&Object.values(a.properties).some((a=>"object"==typeof a&&"default"in a)))(e))return Object.keys(r).reduce(((e,n)=>{const o=r[n];return!o||a(o)||"default"in o&&!i(o.default)&&(e[n]=o.default),e}),{})},g=new Set(["$disable","$errors","$experiment","$extend","$flush","$fork","$toJson","$validate","$values"]),b=a=>g.has(a),y=a=>"object"==typeof a,E=a=>a.additionalProperties&&"object"==typeof a.additionalProperties&&"default"in a.additionalProperties,P=a=>"function"==typeof a,M=(a,i=!1)=>!i&&void 0!==a,S=(a,i=0)=>{if(e(a)){const e=a;return!0===e.__zcb||!!(i<1&&Object.values(e).every((a=>S(a,i+1))))}return!Array.isArray(a)||!!a.every((a=>S(a,i+1)))},k=(a,i)=>i instanceof u?A(i,{errorMessages:!0}):i,v=(a,i)=>Promise.all(a.map((a=>e(a)?B(a,i):Array.isArray(a)?v(a,i):a))),B=async(a,i=[])=>{let n={};const o=r(i);for(const i of o){const e=await Promise.resolve(i(n,a));if(e.action===m.DELETE_NODE)return{};if(e.value&&(n=e.value),e.action===m.SKIP_NODE)return n}for(const r in a){const o=a[r];e(o)?n[r]=await B(o,i):Array.isArray(o)?n[r]=await v(o,i):n[r]=o}return n},C=(a,i)=>a.map((a=>e(a)?_(a,i):Array.isArray(a)?C(a,i):a)),_=(a,i=[])=>{let n={};const o=r(i);for(const i of o){const e=i(n,a);if(e.action===m.DELETE_NODE)return{};if(e.value&&(n=e.value),e.action===m.SKIP_NODE)return n}for(const r in a){const o=a[r];e(o)?n[r]=_(o,i):Array.isArray(o)?n[r]=C(o,i):n[r]=o}return n},T=(a,i={},e={},r={})=>{const t=A(a);if("object"!==t.type)throw new Error(`The root type of a config schema must be "object", but received "${String(t.type)}"`);const c=i.overrides?.uuid??s,u=()=>{const a=n(o(r),(a=>{const i={};for(const e in a.properties){if(b(e))throw new Error(`"${e}" is a reserved keyword within the config builder. Please use a different property name. The full list of reserved keywords is: ${[...g].join(", ")}`);const r=e,n=a.properties[e];if(y(n)){if(n.default&&(i[r]=n.default),"array"===n.type&&p(n))throw new Error(`When setting schema array defaults for the array assigned to "${String(r)}", set them on the array and not the item.`);if("object"===n.type){if(E(n))throw new Error(`When setting schema property defaults for the value of the record assigned to "${String(r)}", set them on the record and not the value.`);const a=h(n);a&&(i[r]=a)}}}return i})(t));var e;return e=a,Object.defineProperty(e,l.ZCB,{configurable:!1,enumerable:!1,value:!0}),Object.defineProperty(e,l.ID,{configurable:!1,enumerable:!1,value:c()}),i.type&&Object.defineProperty(e,l.TYPE,{configurable:!1,enumerable:!1,value:i.type}),a};let m=u(),d={...e};const v={$disable:()=>(Object.defineProperty(m,l.DISABLED,{configurable:!1,enumerable:!1,value:!0}),v),$errors:()=>{try{return a.parse(v.$values()),[]}catch(a){return a.errors}},$experiment:a=>(Object.defineProperty(m,l.EXPERIMENT,{configurable:!1,enumerable:!1,value:a}),v),$extend:a=>{m=_(a.$values(),[f]),d={...a.__callbacks}},$flush:()=>{const a=v.$values();return m=u(),a},$fork:()=>T(a,i,e,r),$toJson:()=>JSON.stringify(v.$values(),k,2),$validate:()=>{try{return a.parse(v.$values()),!0}catch(a){return console.error(a),!1}},$values:()=>{for(const a in d){const i=d[a];i&&(m[a]=i(m))}return m}};Object.defineProperty(v,l.CALLBACKS,{configurable:!1,enumerable:!1,value:d});for(const a in t.properties){if(b(a))throw new Error(`"${a}" is a reserved keyword within the config builder. Please use a different property name. The full list of reserved keywords is: ${[...g].join(", ")}`);const i=a;v[i]=(a,e)=>{if(M(m[i],e))throw new Error(`A value already exists for "${String(i)}". You may be trying to add a new values before flushing the old one. If you intended to override the existing value, pass in true as the second argument.`);let r;if(!S(a))throw new Error(`"${String(i)}" value has a depth greater than 1. To pass in objects with a depth greater than 1, create a builder for that config slice.`);return P(a)?(d[i]=a,r=a(m)):r=a,m[i]=r,v}}return v},I=async(a,{experimentsCallback:i}={})=>{const e=[];var r;return i&&e.push((r=i,async(a,i)=>{if(l.EXPERIMENT in i&&"object"==typeof i.__experiment){const{buckets:a,id:e}=i.__experiment,n=await r(e);if(n&&n in a&&a[n])return a[n]}return{value:a}})),e.length>0?await B(a,e):a},N=a=>({read:(i,{vars:e}={})=>{if(!e)return t(a,i);const r=t(a,i);if(!c(r))throw new Error("config reader received variables to use in string template, but the path did not resolve to a string.");return Object.keys(e).reduce(((a,i)=>a.replace(new RegExp(`{{${i}}}`),String(e[i]))),r)},scope:i=>N(t(a,i))}),w=["AF","AX","AL","DZ","AS","AD","AO","AI","AQ","AG","AR","AM","AW","AU","AT","AZ","BS","BH","BD","BB","BY","BE","BZ","BJ","BM","BT","BO","BA","BW","BV","BR","IO","BN","BG","BF","BI","KH","CM","CA","CV","KY","CF","TD","CL","CN","CX","CC","CO","KM","CG","CD","CK","CR","CI","HR","CU","CY","CZ","DK","DJ","DM","DO","EC","EG","SV","GQ","ER","EE","ET","FK","FO","FJ","FI","FR","GF","PF","TF","GA","GM","GE","DE","GH","GI","GR","GL","GD","GP","GU","GT","GG","GN","GW","GY","HT","HM","VA","HN","HK","HU","IS","IN","ID","IR","IQ","IE","IM","IL","IT","JM","JP","JE","JO","KZ","KE","KI","KR","KW","KG","LA","LV","LB","LS","LR","LY","LI","LT","LU","MO","MK","MG","MW","MY","MV","ML","MT","MH","MQ","MR","MU","YT","MX","FM","MD","MC","MN","ME","MS","MA","MZ","MM","NA","NR","NP","NL","AN","NC","NZ","NI","NE","NG","NU","NF","MP","NO","OM","PK","PW","PS","PA","PG","PY","PE","PH","PN","PL","PT","PR","QA","RE","RO","RU","RW","BL","SH","KN","LC","MF","PM","VC","WS","SM","ST","SA","SN","RS","SC","SL","SG","SK","SI","SB","SO","ZA","GS","ES","LK","SD","SR","SJ","SZ","SE","CH","SY","TW","TJ","TZ","TH","TL","TG","TK","TO","TT","TN","TR","TM","TC","TV","UG","UA","AE","GB","US","UM","UY","UZ","VU","VE","VN","VG","VI","WF","EH","YE","ZM","ZW"],G=["Afghanistan","Albania","Algeria","Andorra","Angola","Anguilla","Antigua and Barbuda","Argentina","Armenia","Aruba","Australia","Austria","Azerbaijan","Bahamas","Bahrain","Bangladesh","Barbados","Belarus","Belgium","Belize","Benin","Bermuda","Bhutan","Bolivia","Bosnia and Herzegovina","Botswana","Brazil","British Virgin Islands","Brunei","Bulgaria","Burkina Faso","Burundi","Cambodia","Cameroon","Cape Verde","Cayman Islands","Chad","Chile","China","Colombia","Congo","Cook Islands","Costa Rica","Cote D Ivoire","Croatia","Cruise Ship","Cuba","Cyprus","Czech Republic","Denmark","Djibouti","Dominica","Dominican Republic","Ecuador","Egypt","El Salvador","Equatorial Guinea","Estonia","Ethiopia","Falkland Islands","Faroe Islands","Fiji","Finland","France","French Polynesia","French West Indies","Gabon","Gambia","Georgia","Germany","Ghana","Gibraltar","Greece","Greenland","Grenada","Guam","Guatemala","Guernsey","Guinea","Guinea Bissau","Guyana","Haiti","Honduras","Hong Kong","Hungary","Iceland","India","Indonesia","Iran","Iraq","Ireland","Isle of Man","Israel","Italy","Jamaica","Japan","Jersey","Jordan","Kazakhstan","Kenya","Kuwait","Kyrgyz Republic","Laos","Latvia","Lebanon","Lesotho","Liberia","Libya","Liechtenstein","Lithuania","Luxembourg","Macau","Macedonia","Madagascar","Malawi","Malaysia","Maldives","Mali","Malta","Mauritania","Mauritius","Mexico","Moldova","Monaco","Mongolia","Montenegro","Montserrat","Morocco","Mozambique","Namibia","Nepal","Netherlands","Netherlands Antilles","New Caledonia","New Zealand","Nicaragua","Niger","Nigeria","Norway","Oman","Pakistan","Palestine","Panama","Papua New Guinea","Paraguay","Peru","Philippines","Poland","Portugal","Puerto Rico","Qatar","Reunion","Romania","Russia","Rwanda","Saint Pierre and Miquelon","Samoa","San Marino","Satellite","Saudi Arabia","Senegal","Serbia","Seychelles","Sierra Leone","Singapore","Slovakia","Slovenia","South Africa","South Korea","Spain","Sri Lanka","St Kitts and Nevis","St Lucia","St Vincent","St. Lucia","Sudan","Suriname","Swaziland","Sweden","Switzerland","Syria","Taiwan","Tajikistan","Tanzania","Thailand","Timor L'Este","Togo","Tonga","Trinidad and Tobago","Tunisia","Turkey","Turkmenistan","Turks and Caicos","Uganda","Ukraine","United Arab Emirates","United Kingdom","Uruguay","Uzbekistan","Venezuela","Vietnam","Virgin Islands (US)","Yemen","Zambia","Zimbabwe"],L=["km","mi"],D=["aa","ab","ae","af","ak","am","an","ar","as","av","ay","az","ba","be","bg","bi","bm","bn","bo","br","bs","ca","ce","ch","co","cr","cs","cu","cv","cy","da","de","dv","dz","ee","el","en","eo","es","et","eu","fa","ff","fi","fj","fo","fr","fy","ga","gd","gl","gn","gu","gv","ha","he","hi","ho","hr","ht","hu","hy","hz","ia","id","ie","ig","ii","ik","io","is","it","iu","ja","jv","ka","kg","ki","kj","kk","kl","km","kn","ko","kr","ks","ku","kv","kw","ky","la","lb","lg","li","ln","lo","lt","lu","lv","mg","mh","mi","mk","ml","mn","mr","ms","mt","my","na","nb","nd","ne","ng","nl","nn","no","nr","nv","ny","oc","oj","om","or","os","pa","pi","pl","ps","pt","qu","rm","rn","ro","ru","rw","sa","sc","sd","se","sg","si","sk","sl","sm","sn","so","sq","sr","ss","st","su","sv","sw","ta","te","tg","th","ti","tk","tl","tn","to","tr","ts","tt","tw","ty","ug","uk","ur","uz","ve","vi","vo","wa","wo","xh","yi","yo","za","zh","zu"],K=["Africa/Abidjan","Africa/Accra","Africa/Addis_Ababa","Africa/Algiers","Africa/Asmara","Africa/Bamako","Africa/Bangui","Africa/Banjul","Africa/Bissau","Africa/Blantyre","Africa/Brazzaville","Africa/Bujumbura","Africa/Cairo","Africa/Casablanca","Africa/Ceuta","Africa/Conakry","Africa/Dakar","Africa/Dar_es_Salaam","Africa/Djibouti","Africa/Douala","Africa/El_Aaiun","Africa/Freetown","Africa/Gaborone","Africa/Harare","Africa/Johannesburg","Africa/Juba","Africa/Kampala","Africa/Khartoum","Africa/Kigali","Africa/Kinshasa","Africa/Lagos","Africa/Libreville","Africa/Lome","Africa/Luanda","Africa/Lubumbashi","Africa/Lusaka","Africa/Malabo","Africa/Maputo","Africa/Maseru","Africa/Mbabane","Africa/Mogadishu","Africa/Monrovia","Africa/Nairobi","Africa/Ndjamena","Africa/Niamey","Africa/Nouakchott","Africa/Ouagadougou","Africa/Porto-Novo","Africa/Sao_Tome","Africa/Tripoli","Africa/Tunis","Africa/Windhoek","America/Adak","America/Anchorage","America/Anguilla","America/Antigua","America/Araguaina","America/Argentina/Buenos_Aires","America/Argentina/Catamarca","America/Argentina/Cordoba","America/Argentina/Jujuy","America/Argentina/La_Rioja","America/Argentina/Mendoza","America/Argentina/Rio_Gallegos","America/Argentina/Salta","America/Argentina/San_Juan","America/Argentina/San_Luis","America/Argentina/Tucuman","America/Argentina/Ushuaia","America/Aruba","America/Asuncion","America/Atikokan","America/Bahia","America/Bahia_Banderas","America/Barbados","America/Belem","America/Belize","America/Blanc-Sablon","America/Boa_Vista","America/Bogota","America/Boise","America/Cambridge_Bay","America/Campo_Grande","America/Cancun","America/Caracas","America/Cayenne","America/Cayman","America/Chicago","America/Chihuahua","America/Costa_Rica","America/Creston","America/Cuiaba","America/Curacao","America/Danmarkshavn","America/Dawson","America/Dawson_Creek","America/Denver","America/Detroit","America/Dominica","America/Edmonton","America/Eirunepe","America/El_Salvador","America/Fort_Nelson","America/Fortaleza","America/Glace_Bay","America/Godthab","America/Goose_Bay","America/Grand_Turk","America/Grenada","America/Guadeloupe","America/Guatemala","America/Guayaquil","America/Guyana","America/Halifax","America/Havana","America/Hermosillo","America/Indiana/Indianapolis","America/Indiana/Knox","America/Indiana/Marengo","America/Indiana/Petersburg","America/Indiana/Tell_City","America/Indiana/Vevay","America/Indiana/Vincennes","America/Indiana/Winamac","America/Inuvik","America/Iqaluit","America/Jamaica","America/Juneau","America/Kentucky/Louisville","America/Kentucky/Monticello","America/Kralendijk","America/La_Paz","America/Lima","America/Los_Angeles","America/Lower_Princes","America/Maceio","America/Managua","America/Manaus","America/Marigot","America/Martinique","America/Matamoros","America/Mazatlan","America/Menominee","America/Merida","America/Metlakatla","America/Mexico_City","America/Miquelon","America/Moncton","America/Monterrey","America/Montevideo","America/Montserrat","America/Nassau","America/New_York","America/Nipigon","America/Nome","America/Noronha","America/North_Dakota/Beulah","America/North_Dakota/Center","America/North_Dakota/New_Salem","America/Ojinaga","America/Panama","America/Pangnirtung","America/Paramaribo","America/Phoenix","America/Port-au-Prince","America/Port_of_Spain","America/Porto_Velho","America/Puerto_Rico","America/Rainy_River","America/Rankin_Inlet","America/Recife","America/Regina","America/Resolute","America/Rio_Branco","America/Santa_Isabel","America/Santarem","America/Santiago","America/Santo_Domingo","America/Sao_Paulo","America/Scoresbysund","America/Sitka","America/St_Barthelemy","America/St_Johns","America/St_Kitts","America/St_Lucia","America/St_Thomas","America/St_Vincent","America/Swift_Current","America/Tegucigalpa","America/Thule","America/Thunder_Bay","America/Tijuana","America/Toronto","America/Tortola","America/Vancouver","America/Whitehorse","America/Winnipeg","America/Yakutat","America/Yellowknife","Antarctica/Casey","Antarctica/Davis","Antarctica/DumontDUrville","Antarctica/Macquarie","Antarctica/Mawson","Antarctica/McMurdo","Antarctica/Palmer","Antarctica/Rothera","Antarctica/Syowa","Antarctica/Troll","Antarctica/Vostok","Arctic/Longyearbyen","Asia/Aden","Asia/Almaty","Asia/Amman","Asia/Anadyr","Asia/Aqtau","Asia/Aqtobe","Asia/Ashgabat","Asia/Baghdad","Asia/Bahrain","Asia/Baku","Asia/Bangkok","Asia/Beirut","Asia/Bishkek","Asia/Brunei","Asia/Chita","Asia/Choibalsan","Asia/Colombo","Asia/Damascus","Asia/Dhaka","Asia/Dili","Asia/Dubai","Asia/Dushanbe","Asia/Gaza","Asia/Hebron","Asia/Ho_Chi_Minh","Asia/Hong_Kong","Asia/Hovd","Asia/Irkutsk","Asia/Jakarta","Asia/Jayapura","Asia/Jerusalem","Asia/Kabul","Asia/Kamchatka","Asia/Karachi","Asia/Kathmandu","Asia/Khandyga","Asia/Kolkata","Asia/Krasnoyarsk","Asia/Kuala_Lumpur","Asia/Kuching","Asia/Kuwait","Asia/Macau","Asia/Magadan","Asia/Makassar","Asia/Manila","Asia/Muscat","Asia/Nicosia","Asia/Novokuznetsk","Asia/Novosibirsk","Asia/Omsk","Asia/Oral","Asia/Phnom_Penh","Asia/Pontianak","Asia/Pyongyang","Asia/Qatar","Asia/Qyzylorda","Asia/Rangoon","Asia/Riyadh","Asia/Sakhalin","Asia/Samarkand","Asia/Seoul","Asia/Shanghai","Asia/Singapore","Asia/Srednekolymsk","Asia/Taipei","Asia/Tashkent","Asia/Tbilisi","Asia/Tehran","Asia/Thimphu","Asia/Tokyo","Asia/Ulaanbaatar","Asia/Urumqi","Asia/Ust-Nera","Asia/Vientiane","Asia/Vladivostok","Asia/Yakutsk","Asia/Yekaterinburg","Asia/Yerevan","Atlantic/Azores","Atlantic/Bermuda","Atlantic/Canary","Atlantic/Cape_Verde","Atlantic/Faroe","Atlantic/Madeira","Atlantic/Reykjavik","Atlantic/South_Georgia","Atlantic/St_Helena","Atlantic/Stanley","Australia/Adelaide","Australia/Brisbane","Australia/Broken_Hill","Australia/Currie","Australia/Darwin","Australia/Eucla","Australia/Hobart","Australia/Lindeman","Australia/Lord_Howe","Australia/Melbourne","Australia/Perth","Australia/Sydney","Europe/Amsterdam","Europe/Andorra","Europe/Athens","Europe/Belgrade","Europe/Berlin","Europe/Bratislava","Europe/Brussels","Europe/Bucharest","Europe/Budapest","Europe/Busingen","Europe/Chisinau","Europe/Copenhagen","Europe/Dublin","Europe/Gibraltar","Europe/Guernsey","Europe/Helsinki","Europe/Isle_of_Man","Europe/Istanbul","Europe/Jersey","Europe/Kaliningrad","Europe/Kiev","Europe/Lisbon","Europe/Ljubljana","Europe/London","Europe/Luxembourg","Europe/Madrid","Europe/Malta","Europe/Mariehamn","Europe/Minsk","Europe/Monaco","Europe/Moscow","Europe/Oslo","Europe/Paris","Europe/Podgorica","Europe/Prague","Europe/Riga","Europe/Rome","Europe/Samara","Europe/San_Marino","Europe/Sarajevo","Europe/Simferopol","Europe/Skopje","Europe/Sofia","Europe/Stockholm","Europe/Tallinn","Europe/Tirane","Europe/Uzhgorod","Europe/Vaduz","Europe/Vatican","Europe/Vienna","Europe/Vilnius","Europe/Volgograd","Europe/Warsaw","Europe/Zagreb","Europe/Zaporozhye","Europe/Zurich","Indian/Antananarivo","Indian/Chagos","Indian/Christmas","Indian/Cocos","Indian/Comoro","Indian/Kerguelen","Indian/Mahe","Indian/Maldives","Indian/Mauritius","Indian/Mayotte","Indian/Reunion","Pacific/Apia","Pacific/Auckland","Pacific/Bougainville","Pacific/Chatham","Pacific/Chuuk","Pacific/Easter","Pacific/Efate","Pacific/Enderbury","Pacific/Fakaofo","Pacific/Fiji","Pacific/Funafuti","Pacific/Galapagos","Pacific/Gambier","Pacific/Guadalcanal","Pacific/Guam","Pacific/Honolulu","Pacific/Johnston","Pacific/Kiritimati","Pacific/Kosrae","Pacific/Kwajalein","Pacific/Majuro","Pacific/Marquesas","Pacific/Midway","Pacific/Nauru","Pacific/Niue","Pacific/Norfolk","Pacific/Noumea","Pacific/Pago_Pago","Pacific/Palau","Pacific/Pitcairn","Pacific/Pohnpei","Pacific/Port_Moresby","Pacific/Rarotonga","Pacific/Saipan","Pacific/Tahiti","Pacific/Tarawa","Pacific/Tongatapu","Pacific/Wake","Pacific/Wallis"];export{l as NonEmumeralProperties,m as TransformConfigHandlerAction,f as cloneNonEnumerableValues,w as countryCodes,G as countryNames,T as createConfigBuilder,I as createConfigParser,N as createConfigReader,L as distanceUnits,D as languageCodes,K as timezones};
|
|
373
2
|
//# sourceMappingURL=index.mjs.map
|