Init: RoggioApp Architecture, Prisma Schema, API MVP
This commit is contained in:
+25
@@ -0,0 +1,25 @@
|
||||
# Licenses of Bundled Dependencies
|
||||
|
||||
The published artifact additionally contains code with the following licenses:
|
||||
BSD-3-Clause
|
||||
|
||||
# Bundled Dependencies
|
||||
|
||||
## flat
|
||||
|
||||
License: BSD-3-Clause
|
||||
By: Hugh Kennedy
|
||||
Repository: https://github.com/hughsk/flat
|
||||
|
||||
> Copyright (c) 2014, Hugh Kennedy
|
||||
> All rights reserved.
|
||||
>
|
||||
> Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
>
|
||||
> 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
>
|
||||
> 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
>
|
||||
> 3. Neither the name of the nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
>
|
||||
> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
//#region node_modules/.pnpm/flat@6.0.1/node_modules/flat/index.js
|
||||
function isBuffer(obj) {
|
||||
return obj && obj.constructor && typeof obj.constructor.isBuffer === "function" && obj.constructor.isBuffer(obj);
|
||||
}
|
||||
function keyIdentity(key) {
|
||||
return key;
|
||||
}
|
||||
function flatten(target, opts) {
|
||||
opts = opts || {};
|
||||
const delimiter = opts.delimiter || ".";
|
||||
const maxDepth = opts.maxDepth;
|
||||
const transformKey = opts.transformKey || keyIdentity;
|
||||
const output = {};
|
||||
function step(object, prev, currentDepth) {
|
||||
currentDepth = currentDepth || 1;
|
||||
Object.keys(object).forEach(function(key) {
|
||||
const value = object[key];
|
||||
const isarray = opts.safe && Array.isArray(value);
|
||||
const type = Object.prototype.toString.call(value);
|
||||
const isbuffer = isBuffer(value);
|
||||
const isobject = type === "[object Object]" || type === "[object Array]";
|
||||
const newKey = prev ? prev + delimiter + transformKey(key) : transformKey(key);
|
||||
if (!isarray && !isbuffer && isobject && Object.keys(value).length && (!opts.maxDepth || currentDepth < maxDepth)) return step(value, newKey, currentDepth + 1);
|
||||
output[newKey] = value;
|
||||
});
|
||||
}
|
||||
step(target);
|
||||
return output;
|
||||
}
|
||||
function unflatten(target, opts) {
|
||||
opts = opts || {};
|
||||
const delimiter = opts.delimiter || ".";
|
||||
const overwrite = opts.overwrite || false;
|
||||
const transformKey = opts.transformKey || keyIdentity;
|
||||
const result = {};
|
||||
if (isBuffer(target) || Object.prototype.toString.call(target) !== "[object Object]") return target;
|
||||
function getkey(key) {
|
||||
const parsedKey = Number(key);
|
||||
return isNaN(parsedKey) || key.indexOf(".") !== -1 || opts.object ? key : parsedKey;
|
||||
}
|
||||
function addKeys(keyPrefix, recipient, target) {
|
||||
return Object.keys(target).reduce(function(result, key) {
|
||||
result[keyPrefix + delimiter + key] = target[key];
|
||||
return result;
|
||||
}, recipient);
|
||||
}
|
||||
function isEmpty(val) {
|
||||
const type = Object.prototype.toString.call(val);
|
||||
const isArray = type === "[object Array]";
|
||||
const isObject = type === "[object Object]";
|
||||
if (!val) return true;
|
||||
else if (isArray) return !val.length;
|
||||
else if (isObject) return !Object.keys(val).length;
|
||||
}
|
||||
target = Object.keys(target).reduce(function(result, key) {
|
||||
const type = Object.prototype.toString.call(target[key]);
|
||||
if (!(type === "[object Object]" || type === "[object Array]") || isEmpty(target[key])) {
|
||||
result[key] = target[key];
|
||||
return result;
|
||||
} else return addKeys(key, result, flatten(target[key], opts));
|
||||
}, {});
|
||||
Object.keys(target).forEach(function(key) {
|
||||
const split = key.split(delimiter).map(transformKey);
|
||||
let key1 = getkey(split.shift());
|
||||
let key2 = getkey(split[0]);
|
||||
let recipient = result;
|
||||
while (key2 !== void 0) {
|
||||
if (key1 === "__proto__") return;
|
||||
const type = Object.prototype.toString.call(recipient[key1]);
|
||||
const isobject = type === "[object Object]" || type === "[object Array]";
|
||||
if (!overwrite && !isobject && typeof recipient[key1] !== "undefined") return;
|
||||
if (overwrite && !isobject || !overwrite && recipient[key1] == null) recipient[key1] = typeof key2 === "number" && !opts.object ? [] : {};
|
||||
recipient = recipient[key1];
|
||||
if (split.length > 0) {
|
||||
key1 = getkey(split.shift());
|
||||
key2 = getkey(split[0]);
|
||||
}
|
||||
}
|
||||
recipient[key1] = unflatten(target[key], opts);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
//#endregion
|
||||
export { unflatten as n, flatten as t };
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
//#region src/index.d.ts
|
||||
type RC = Record<string, any>;
|
||||
interface RCOptions {
|
||||
/**
|
||||
* The name of the configuration file.
|
||||
* @optional
|
||||
*/
|
||||
name?: string;
|
||||
/**
|
||||
* The directory where the configuration file is or should be written.
|
||||
* @optional
|
||||
*/
|
||||
dir?: string;
|
||||
/**
|
||||
* Specifies whether the configuration should be treated as a flat object.
|
||||
* @optional
|
||||
*/
|
||||
flat?: boolean;
|
||||
}
|
||||
/**
|
||||
* The default options for the configuration file.
|
||||
*/
|
||||
declare const defaults: RCOptions;
|
||||
declare function parse<T extends RC = RC>(contents: string, options?: RCOptions): T;
|
||||
/**
|
||||
* Parses a configuration string into an object.
|
||||
* @param {string} contents - The configuration data as a raw string.
|
||||
* @param {RCOptions} [options={}] - Options to control the parsing behaviour. See {@link RCOptions}.
|
||||
* @returns {RC} - The parsed configuration object. See {@link RC}.
|
||||
*/
|
||||
declare function parseFile<T extends RC = RC>(path: string, options?: RCOptions): T;
|
||||
/**
|
||||
* Reads a configuration file from a default or specified location and parses its contents.
|
||||
* @param {RCOptions|string} [options] - Options for reading the configuration file, or the name of the configuration file. See {@link RCOptions}.
|
||||
* @returns {RC} - The parsed configuration object. See {@link RC}.
|
||||
*/
|
||||
declare function read<T extends RC = RC>(options?: RCOptions | string): T;
|
||||
/**
|
||||
* Reads a custom configuration file from a default or specified location and parses its contents.
|
||||
* @param {RCOptions|string} [options] - Options for reading the configuration file, or the name of the configuration file. See {@link RCOptions}.
|
||||
* @returns {RC} - The parsed configuration object.
|
||||
* @deprecated Use {@link readUserConfig} instead, which uses `~/.config` following XDG conventions.
|
||||
*/
|
||||
declare function readUser<T extends RC = RC>(options?: RCOptions | string): T;
|
||||
/**
|
||||
* Serialises a configuration object to a string format.
|
||||
* @param {RC} config - The configuration object to serialise. See {@link RC}.
|
||||
* @returns {string} - The serialised configuration string.
|
||||
*/
|
||||
declare function serialize<T extends RC = RC>(config: T): string;
|
||||
/**
|
||||
* Writes a configuration object to a file in a default or specified location.
|
||||
* @param {RC} config - The configuration object to write. See {@link RC}.
|
||||
* @param {RCOptions|string} [options] - Options for writing the configuration file, or the name of the configuration file. See {@link RCOptions}.
|
||||
*/
|
||||
declare function write<T extends RC = RC>(config: T, options?: RCOptions | string): void;
|
||||
/**
|
||||
* Writes a custom configuration object to a file in a default or specified location.
|
||||
* @param {RC} config - The configuration object to write. See {@link RC}.
|
||||
* @param {RCOptions|string} [options] - Options for writing the configuration file, or the name of the configuration file. See {@link RCOptions}.
|
||||
* @deprecated Use {@link writeUserConfig} instead, which uses `~/.config` following XDG conventions.
|
||||
*/
|
||||
declare function writeUser<T extends RC = RC>(config: T, options?: RCOptions | string): void;
|
||||
/**
|
||||
* Reads a configuration file from `$XDG_CONFIG_HOME` or `$HOME/.config` and parses its contents.
|
||||
* @param {RCOptions|string} [options] - Options for reading the configuration file, or the name of the configuration file. See {@link RCOptions}.
|
||||
* @returns {RC} - The parsed configuration object.
|
||||
*/
|
||||
declare function readUserConfig<T extends RC = RC>(options?: RCOptions | string): T;
|
||||
/**
|
||||
* Writes a configuration object to a file in `$XDG_CONFIG_HOME` or `$HOME/.config`.
|
||||
* @param {RC} config - The configuration object to write. See {@link RC}.
|
||||
* @param {RCOptions|string} [options] - Options for writing the configuration file, or the name of the configuration file. See {@link RCOptions}.
|
||||
*/
|
||||
declare function writeUserConfig<T extends RC = RC>(config: T, options?: RCOptions | string): void;
|
||||
/**
|
||||
* Updates a configuration object in `$XDG_CONFIG_HOME` or `$HOME/.config` by merging and writing the result.
|
||||
* @param {RC} config - The configuration object to update. See {@link RC}.
|
||||
* @param {RCOptions|string} [options] - Options for updating the configuration file, or the name of the configuration file. See {@link RCOptions}.
|
||||
* @returns {RC} - The updated configuration object.
|
||||
*/
|
||||
declare function updateUserConfig<T extends RC = RC>(config: T, options?: RCOptions | string): T;
|
||||
/**
|
||||
* Updates an existing configuration object by merging it with the contents of a configuration file and writing the result.
|
||||
* @param {RC} config - The configuration object to update. See {@link RC}.
|
||||
* @param {RCOptions|string} [options] - Options for updating the configuration file, or the name of the configuration file. See {@link RCOptions}.
|
||||
* @returns {RC} - The updated configuration object. See {@link RC}.
|
||||
*/
|
||||
declare function update<T extends RC = RC>(config: T, options?: RCOptions | string): T;
|
||||
/**
|
||||
* Updates a custom configuration object by merging it with the contents of a configuration file in a default location and writing the result.
|
||||
* @param {RC} config - The configuration object to update. See {@link RC}.
|
||||
* @param {RCOptions|string} [options] - Options for updating the configuration file, or the name of the configuration file. See {@link RCOptions}.
|
||||
* @returns {RC} - The updated configuration object. See {@link RC}.
|
||||
* @deprecated Use {@link updateUserConfig} instead, which uses `~/.config` following XDG conventions.
|
||||
*/
|
||||
declare function updateUser<T extends RC = RC>(config: T, options?: RCOptions | string): T;
|
||||
//#endregion
|
||||
export { RC, RCOptions, defaults, parse, parseFile, read, readUser, readUserConfig, serialize, update, updateUser, updateUserConfig, write, writeUser, writeUserConfig };
|
||||
+158
@@ -0,0 +1,158 @@
|
||||
import { n as unflatten, t as flatten } from "./_chunks/libs/flat.mjs";
|
||||
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
||||
import { resolve } from "node:path";
|
||||
import { homedir } from "node:os";
|
||||
import destr from "destr";
|
||||
import { defu } from "defu";
|
||||
//#region src/index.ts
|
||||
const RE_KEY_VAL = /^\s*([^\s=]+)\s*=\s*(.*)?\s*$/;
|
||||
const RE_LINES = /\n|\r|\r\n/;
|
||||
/**
|
||||
* The default options for the configuration file.
|
||||
*/
|
||||
const defaults = {
|
||||
name: ".conf",
|
||||
dir: process.cwd(),
|
||||
flat: false
|
||||
};
|
||||
function withDefaults(options) {
|
||||
if (typeof options === "string") options = { name: options };
|
||||
return {
|
||||
...defaults,
|
||||
...options
|
||||
};
|
||||
}
|
||||
function parse(contents, options = {}) {
|
||||
const config = {};
|
||||
const lines = contents.split(RE_LINES);
|
||||
for (const line of lines) {
|
||||
const match = line.match(RE_KEY_VAL);
|
||||
if (!match) continue;
|
||||
const key = match[1];
|
||||
if (!key || key === "__proto__" || key === "constructor") continue;
|
||||
const value = destr((match[2] || "").trim());
|
||||
if (key.endsWith("[]")) {
|
||||
const nkey = key.slice(0, Math.max(0, key.length - 2));
|
||||
config[nkey] = (config[nkey] || []).concat(value);
|
||||
continue;
|
||||
}
|
||||
config[key] = value;
|
||||
}
|
||||
return options.flat ? config : unflatten(config, { overwrite: true });
|
||||
}
|
||||
/**
|
||||
* Parses a configuration string into an object.
|
||||
* @param {string} contents - The configuration data as a raw string.
|
||||
* @param {RCOptions} [options={}] - Options to control the parsing behaviour. See {@link RCOptions}.
|
||||
* @returns {RC} - The parsed configuration object. See {@link RC}.
|
||||
*/
|
||||
function parseFile(path, options) {
|
||||
if (!existsSync(path)) return {};
|
||||
return parse(readFileSync(path, "utf8"), options);
|
||||
}
|
||||
/**
|
||||
* Reads a configuration file from a default or specified location and parses its contents.
|
||||
* @param {RCOptions|string} [options] - Options for reading the configuration file, or the name of the configuration file. See {@link RCOptions}.
|
||||
* @returns {RC} - The parsed configuration object. See {@link RC}.
|
||||
*/
|
||||
function read(options) {
|
||||
options = withDefaults(options);
|
||||
return parseFile(resolve(options.dir, options.name), options);
|
||||
}
|
||||
/**
|
||||
* Reads a custom configuration file from a default or specified location and parses its contents.
|
||||
* @param {RCOptions|string} [options] - Options for reading the configuration file, or the name of the configuration file. See {@link RCOptions}.
|
||||
* @returns {RC} - The parsed configuration object.
|
||||
* @deprecated Use {@link readUserConfig} instead, which uses `~/.config` following XDG conventions.
|
||||
*/
|
||||
function readUser(options) {
|
||||
options = withDefaults(options);
|
||||
options.dir = process.env.XDG_CONFIG_HOME || homedir();
|
||||
return read(options);
|
||||
}
|
||||
/**
|
||||
* Serialises a configuration object to a string format.
|
||||
* @param {RC} config - The configuration object to serialise. See {@link RC}.
|
||||
* @returns {string} - The serialised configuration string.
|
||||
*/
|
||||
function serialize(config) {
|
||||
return Object.entries(flatten(config)).map(([key, value]) => `${key}=${JSON.stringify(value)}`).join("\n");
|
||||
}
|
||||
/**
|
||||
* Writes a configuration object to a file in a default or specified location.
|
||||
* @param {RC} config - The configuration object to write. See {@link RC}.
|
||||
* @param {RCOptions|string} [options] - Options for writing the configuration file, or the name of the configuration file. See {@link RCOptions}.
|
||||
*/
|
||||
function write(config, options) {
|
||||
options = withDefaults(options);
|
||||
writeFileSync(resolve(options.dir, options.name), serialize(config), { encoding: "utf8" });
|
||||
}
|
||||
/**
|
||||
* Writes a custom configuration object to a file in a default or specified location.
|
||||
* @param {RC} config - The configuration object to write. See {@link RC}.
|
||||
* @param {RCOptions|string} [options] - Options for writing the configuration file, or the name of the configuration file. See {@link RCOptions}.
|
||||
* @deprecated Use {@link writeUserConfig} instead, which uses `~/.config` following XDG conventions.
|
||||
*/
|
||||
function writeUser(config, options) {
|
||||
options = withDefaults(options);
|
||||
options.dir = process.env.XDG_CONFIG_HOME || homedir();
|
||||
write(config, options);
|
||||
}
|
||||
/**
|
||||
* Reads a configuration file from `$XDG_CONFIG_HOME` or `$HOME/.config` and parses its contents.
|
||||
* @param {RCOptions|string} [options] - Options for reading the configuration file, or the name of the configuration file. See {@link RCOptions}.
|
||||
* @returns {RC} - The parsed configuration object.
|
||||
*/
|
||||
function readUserConfig(options) {
|
||||
options = withDefaults(options);
|
||||
options.dir = process.env.XDG_CONFIG_HOME || resolve(homedir(), ".config");
|
||||
return read(options);
|
||||
}
|
||||
/**
|
||||
* Writes a configuration object to a file in `$XDG_CONFIG_HOME` or `$HOME/.config`.
|
||||
* @param {RC} config - The configuration object to write. See {@link RC}.
|
||||
* @param {RCOptions|string} [options] - Options for writing the configuration file, or the name of the configuration file. See {@link RCOptions}.
|
||||
*/
|
||||
function writeUserConfig(config, options) {
|
||||
options = withDefaults(options);
|
||||
options.dir = process.env.XDG_CONFIG_HOME || resolve(homedir(), ".config");
|
||||
write(config, options);
|
||||
}
|
||||
/**
|
||||
* Updates a configuration object in `$XDG_CONFIG_HOME` or `$HOME/.config` by merging and writing the result.
|
||||
* @param {RC} config - The configuration object to update. See {@link RC}.
|
||||
* @param {RCOptions|string} [options] - Options for updating the configuration file, or the name of the configuration file. See {@link RCOptions}.
|
||||
* @returns {RC} - The updated configuration object.
|
||||
*/
|
||||
function updateUserConfig(config, options) {
|
||||
options = withDefaults(options);
|
||||
options.dir = process.env.XDG_CONFIG_HOME || resolve(homedir(), ".config");
|
||||
return update(config, options);
|
||||
}
|
||||
/**
|
||||
* Updates an existing configuration object by merging it with the contents of a configuration file and writing the result.
|
||||
* @param {RC} config - The configuration object to update. See {@link RC}.
|
||||
* @param {RCOptions|string} [options] - Options for updating the configuration file, or the name of the configuration file. See {@link RCOptions}.
|
||||
* @returns {RC} - The updated configuration object. See {@link RC}.
|
||||
*/
|
||||
function update(config, options) {
|
||||
options = withDefaults(options);
|
||||
if (!options.flat) config = unflatten(config, { overwrite: true });
|
||||
const newConfig = defu(config, read(options));
|
||||
write(newConfig, options);
|
||||
return newConfig;
|
||||
}
|
||||
/**
|
||||
* Updates a custom configuration object by merging it with the contents of a configuration file in a default location and writing the result.
|
||||
* @param {RC} config - The configuration object to update. See {@link RC}.
|
||||
* @param {RCOptions|string} [options] - Options for updating the configuration file, or the name of the configuration file. See {@link RCOptions}.
|
||||
* @returns {RC} - The updated configuration object. See {@link RC}.
|
||||
* @deprecated Use {@link updateUserConfig} instead, which uses `~/.config` following XDG conventions.
|
||||
*/
|
||||
function updateUser(config, options) {
|
||||
options = withDefaults(options);
|
||||
options.dir = process.env.XDG_CONFIG_HOME || homedir();
|
||||
return update(config, options);
|
||||
}
|
||||
//#endregion
|
||||
export { defaults, parse, parseFile, read, readUser, readUserConfig, serialize, update, updateUser, updateUserConfig, write, writeUser, writeUserConfig };
|
||||
Reference in New Issue
Block a user