diff --git a/.github/workflows/npm-publish-github-packages.yml b/.github/workflows/npm-publish-github-packages.yml new file mode 100644 index 0000000..0f838d5 --- /dev/null +++ b/.github/workflows/npm-publish-github-packages.yml @@ -0,0 +1,36 @@ +# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created +# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages + +name: Node.js Package + +on: + release: + types: [created] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v3 + with: + node-version: 16 + - run: npm ci + - run: npm test + + publish-gpr: + needs: build + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v3 + with: + node-version: 16 + registry-url: https://npm.pkg.github.com/ + - run: npm ci + - run: npm publish + env: + NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} diff --git a/dist/localbase.dev.d.ts b/dist/localbase.dev.d.ts new file mode 100644 index 0000000..1cce635 --- /dev/null +++ b/dist/localbase.dev.d.ts @@ -0,0 +1,2 @@ +declare const _exports: any; +export = _exports; diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..4da2a2b --- /dev/null +++ b/index.d.ts @@ -0,0 +1,2 @@ +export default Localbase; +import Localbase from "./localbase/localbase"; diff --git a/localbase/api-utils/error.d.ts b/localbase/api-utils/error.d.ts new file mode 100644 index 0000000..17446c8 --- /dev/null +++ b/localbase/api-utils/error.d.ts @@ -0,0 +1 @@ +export default function error(message: any): string; diff --git a/localbase/api-utils/reset.d.ts b/localbase/api-utils/reset.d.ts new file mode 100644 index 0000000..14817f9 --- /dev/null +++ b/localbase/api-utils/reset.d.ts @@ -0,0 +1,9 @@ +export default function reset(): void; +export default class reset { + collectionName: any; + orderByProperty: any; + orderByDirection: any; + limitBy: any; + docSelectionCriteria: any; + userErrors: any[]; +} diff --git a/localbase/api-utils/selectionLevel.d.ts b/localbase/api-utils/selectionLevel.d.ts new file mode 100644 index 0000000..5b2de0d --- /dev/null +++ b/localbase/api-utils/selectionLevel.d.ts @@ -0,0 +1 @@ +export default function selectionLevel(): string | undefined; diff --git a/localbase/api-utils/showUserErrors.d.ts b/localbase/api-utils/showUserErrors.d.ts new file mode 100644 index 0000000..6325fcb --- /dev/null +++ b/localbase/api-utils/showUserErrors.d.ts @@ -0,0 +1 @@ +export default function showUserErrors(): void; diff --git a/localbase/api-utils/success.d.ts b/localbase/api-utils/success.d.ts new file mode 100644 index 0000000..6e121da --- /dev/null +++ b/localbase/api-utils/success.d.ts @@ -0,0 +1,5 @@ +export default function success(message: any, data: any): { + success: boolean; + message: any; + data: any; +}; diff --git a/localbase/api/actions/add.d.ts b/localbase/api/actions/add.d.ts new file mode 100644 index 0000000..14b34cc --- /dev/null +++ b/localbase/api/actions/add.d.ts @@ -0,0 +1 @@ +export default function add(data: { [key:string]: any }, keyProvided: string): void ; diff --git a/localbase/api/actions/delete.d.ts b/localbase/api/actions/delete.d.ts new file mode 100644 index 0000000..d53b1d7 --- /dev/null +++ b/localbase/api/actions/delete.d.ts @@ -0,0 +1,11 @@ +export default function deleteIt(): any; +export default class deleteIt { + deleteDatabase: () => void; + deleteCollection: () => void; + addToDeleteCollectionQueue: (collectionName: any) => void; + runDeleteCollectionQueue: () => void; + deleteNextCollectionFromQueue: any; + deleteDocument: () => void; + deleteDocumentByCriteria: () => void; + deleteDocumentByKey: () => void; +} diff --git a/localbase/api/actions/get.d.ts b/localbase/api/actions/get.d.ts new file mode 100644 index 0000000..cef101b --- /dev/null +++ b/localbase/api/actions/get.d.ts @@ -0,0 +1,12 @@ +export default function get(options?: { + keys: boolean; +}): any; +export default class get { + constructor(options?: { + keys: boolean; + }); + getCollection: () => any; + getDocument: () => any; + getDocumentByCriteria: () => any; + getDocumentByKey: () => any; +} diff --git a/localbase/api/actions/get.js b/localbase/api/actions/get.js index 5413c7d..dbdac4b 100644 --- a/localbase/api/actions/get.js +++ b/localbase/api/actions/get.js @@ -41,11 +41,13 @@ export default function get(options = { keys: false }) { logMessage += `, ordered by "${ orderByProperty }"` if (!options.keys) { collection.sort((a, b) => { + if (!a.hasOwnProperty(orderByProperty) || !b.hasOwnProperty(orderByProperty)) return 0 return a[orderByProperty].toString().localeCompare(b[orderByProperty].toString()) }) } else { collection.sort((a, b) => { + if (!a.hasOwnProperty(orderByProperty) || !b.hasOwnProperty(orderByProperty)) return 0 return a.data[orderByProperty].toString().localeCompare(b.data[orderByProperty].toString()) }) } diff --git a/localbase/api/actions/set.d.ts b/localbase/api/actions/set.d.ts new file mode 100644 index 0000000..e3fec9e --- /dev/null +++ b/localbase/api/actions/set.d.ts @@ -0,0 +1,12 @@ +export default function set(newDocument: any, options?: { + keys: boolean; +}): any; +export default class set { + constructor(newDocument: any, options?: { + keys: boolean; + }); + setCollection: () => void; + setDocument: () => void; + setDocumentByCriteria: () => void; + setDocumentByKey: () => void; +} diff --git a/localbase/api/actions/update.d.ts b/localbase/api/actions/update.d.ts new file mode 100644 index 0000000..f49256a --- /dev/null +++ b/localbase/api/actions/update.d.ts @@ -0,0 +1,6 @@ +export default function update(docUpdates: any): any; +export default class update { + constructor(docUpdates: any); + updateDocumentByCriteria: () => void; + updateDocumentByKey: () => void; +} diff --git a/localbase/api/filters/limit.d.ts b/localbase/api/filters/limit.d.ts new file mode 100644 index 0000000..2001b39 --- /dev/null +++ b/localbase/api/filters/limit.d.ts @@ -0,0 +1,5 @@ +export default function limit(limitBy: any): this; +export default class limit { + constructor(limitBy: any); + limitBy: any; +} diff --git a/localbase/api/filters/orderBy.d.ts b/localbase/api/filters/orderBy.d.ts new file mode 100644 index 0000000..38604c4 --- /dev/null +++ b/localbase/api/filters/orderBy.d.ts @@ -0,0 +1,6 @@ +export default function orderBy(property: any, direction: any): this; +export default class orderBy { + constructor(property: any, direction: any); + orderByProperty: string | undefined; + orderByDirection: any; +} diff --git a/localbase/api/selectors/collection.d.ts b/localbase/api/selectors/collection.d.ts new file mode 100644 index 0000000..c48fd93 --- /dev/null +++ b/localbase/api/selectors/collection.d.ts @@ -0,0 +1,5 @@ +export default function collection(collectionName: any): this; +export default class collection { + constructor(collectionName: any); + collectionName: string | undefined; +} diff --git a/localbase/api/selectors/doc.d.ts b/localbase/api/selectors/doc.d.ts new file mode 100644 index 0000000..b0ac51a --- /dev/null +++ b/localbase/api/selectors/doc.d.ts @@ -0,0 +1,5 @@ +export default function doc(docSelectionCriteria: any): this; +export default class doc { + constructor(docSelectionCriteria: any); + docSelectionCriteria: any; +} diff --git a/localbase/localbase.d.ts b/localbase/localbase.d.ts new file mode 100644 index 0000000..9a1cacf --- /dev/null +++ b/localbase/localbase.d.ts @@ -0,0 +1,36 @@ +export default class Localbase { + constructor(dbName: any); + dbName: any; + lf: {}; + collectionName: any; + orderByProperty: any; + orderByDirection: any; + limitBy: any; + docSelectionCriteria: any; + deleteCollectionQueue: { + queue: never[]; + running: boolean; + }; + config: { + debug: boolean; + }; + userErrors: any[]; + collection: typeof collection; + doc: typeof doc; + orderBy: typeof orderBy; + limit: typeof limit; + get: typeof get; + add: typeof add; + update: typeof update; + set: typeof set; + delete: typeof deleteIt; +} +import collection from "./api/selectors/collection"; +import doc from "./api/selectors/doc"; +import orderBy from "./api/filters/orderBy"; +import limit from "./api/filters/limit"; +import get from "./api/actions/get"; +import add from "./api/actions/add"; +import update from "./api/actions/update"; +import set from "./api/actions/set"; +import deleteIt from "./api/actions/delete"; diff --git a/localbase/utils/isSubset.d.ts b/localbase/utils/isSubset.d.ts new file mode 100644 index 0000000..4a0bbaf --- /dev/null +++ b/localbase/utils/isSubset.d.ts @@ -0,0 +1 @@ +export default function isSubset(superObj: any, subObj: any): any; diff --git a/localbase/utils/logger.d.ts b/localbase/utils/logger.d.ts new file mode 100644 index 0000000..47a3d0c --- /dev/null +++ b/localbase/utils/logger.d.ts @@ -0,0 +1,15 @@ +export default logger; +declare namespace logger { + const baseStyle: string; + namespace colors { + const log: string; + const error: string; + const warn: string; + } + function log(message: any, secondary: any): void; + function log(message: any, secondary: any): void; + function error(message: any, secondary: any): void; + function error(message: any, secondary: any): void; + function warn(message: any, secondary: any): void; + function warn(message: any, secondary: any): void; +} diff --git a/localbase/utils/updateObject.d.ts b/localbase/utils/updateObject.d.ts new file mode 100644 index 0000000..6023b8e --- /dev/null +++ b/localbase/utils/updateObject.d.ts @@ -0,0 +1 @@ +export default function updateObject(obj: any, ...args: any[]): any; diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..b4a9b3f --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,71 @@ +{ + "compilerOptions": { + /* Visit https://aka.ms/tsconfig.json to read more about this file */ + + /* Basic Options */ + // "incremental": true, /* Enable incremental compilation */ + "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ + "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ + "allowJs": true, /* Allow javascript files to be compiled. */ + "declaration": true, /* Generates corresponding '.d.ts' file. */ + "emitDeclarationOnly": true, /* Generate ONLY '.d.ts' file, no output javascript */ + // "lib": [], /* Specify library files to be included in the compilation. */ + // "checkJs": true, /* Report errors in .js files. */ + // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ + // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ + // "sourceMap": true, /* Generates corresponding '.map' file. */ + // "outFile": "./", /* Concatenate and emit output to single file. */ + // "outDir": "./", /* Redirect output structure to the directory. */ + // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ + // "composite": true, /* Enable project compilation */ + // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ + // "removeComments": true, /* Do not emit comments to output. */ + // "noEmit": true, /* Do not emit outputs. */ + // "importHelpers": true, /* Import emit helpers from 'tslib'. */ + // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ + // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ + + /* Strict Type-Checking Options */ + "strict": true, /* Enable all strict type-checking options. */ + // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* Enable strict null checks. */ + // "strictFunctionTypes": true, /* Enable strict checking of function types. */ + // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ + // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ + // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ + // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ + + /* Additional Checks */ + // "noUnusedLocals": true, /* Report errors on unused locals. */ + // "noUnusedParameters": true, /* Report errors on unused parameters. */ + // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ + // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ + // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ + + /* Module Resolution Options */ + // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ + // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ + // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ + // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ + // "typeRoots": [], /* List of folders to include type definitions from. */ + // "types": [], /* Type declaration files to be included in compilation. */ + // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ + // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + + /* Source Map Options */ + // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ + // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ + + /* Experimental Options */ + // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ + // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + + /* Advanced Options */ + "skipLibCheck": true, /* Skip type checking of declaration files. */ + "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ + } +}