Skip to content

Commit

Permalink
feat(deno): Feathers core build for Deno (feathersjs#2299)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl authored Apr 21, 2021
1 parent 501d416 commit dece8fb
Show file tree
Hide file tree
Showing 31 changed files with 2,027 additions and 23 deletions.
3 changes: 2 additions & 1 deletion .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ exclude_patterns:
- "**/adapter-tests/*"
- "**/dist/*"
- "**/*.dist.js"
- "**/templates/*"
- "**/templates/*"
- "**/_**"
18 changes: 18 additions & 0 deletions .github/workflows/deno.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Deno CI

on: [push, pull_request]

jobs:
test:
runs-on: "ubuntu-latest"
steps:
- name: Setup repo
uses: actions/checkout@v2

- name: Setup Deno
uses: denolib/setup-deno@v2
with:
deno-version: v1.x

- name: Run Tests
run: deno test --config deno/tsconfig.json deno/test.ts
22 changes: 22 additions & 0 deletions deno/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2021 Feathers

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

28 changes: 28 additions & 0 deletions deno/_commons/debug.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// DO NOT MODIFY - generated from packages/commons/src/debug.ts

export type DebugFunction = (...args: any[]) => void;
export type DebugInitializer = (name: string) => DebugFunction;

const debuggers: { [key: string]: DebugFunction } = {};

export function noopDebug (): DebugFunction {
return () => {}
}

let defaultInitializer: DebugInitializer = noopDebug;

export function setDebug (debug: DebugInitializer) {
defaultInitializer = debug;

Object.keys(debuggers).forEach(name => {
debuggers[name] = debug(name);
});
}

export function createDebug (name: string) {
if (!debuggers[name]) {
debuggers[name] = defaultInitializer(name);
}

return (...args: any[]) => debuggers[name](...args);
}
105 changes: 105 additions & 0 deletions deno/_commons/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// DO NOT MODIFY - generated from packages/commons/src/index.ts

// Removes all leading and trailing slashes from a path
export function stripSlashes (name: string) {
return name.replace(/^(\/+)|(\/+)$/g, '');
}

export type KeyValueCallback<T> = (value: any, key: string) => T;

// A set of lodash-y utility functions that use ES6
export const _ = {
each (obj: any, callback: KeyValueCallback<void>) {
if (obj && typeof obj.forEach === 'function') {
obj.forEach(callback);
} else if (_.isObject(obj)) {
Object.keys(obj).forEach(key => callback(obj[key], key));
}
},

some (value: any, callback: KeyValueCallback<boolean>) {
return Object.keys(value)
.map(key => [ value[key], key ])
.some(([val, key]) => callback(val, key));
},

every (value: any, callback: KeyValueCallback<boolean>) {
return Object.keys(value)
.map(key => [ value[key], key ])
.every(([val, key]) => callback(val, key));
},

keys (obj: any) {
return Object.keys(obj);
},

values (obj: any) {
return _.keys(obj).map(key => obj[key]);
},

isMatch (obj: any, item: any) {
return _.keys(item).every(key => obj[key] === item[key]);
},

isEmpty (obj: any) {
return _.keys(obj).length === 0;
},

isObject (item: any) {
return (typeof item === 'object' && !Array.isArray(item) && item !== null);
},

isObjectOrArray (value: any) {
return typeof value === 'object' && value !== null;
},

extend (first: any, ...rest: any[]) {
return Object.assign(first, ...rest);
},

omit (obj: any, ...keys: string[]) {
const result = _.extend({}, obj);
keys.forEach(key => delete result[key]);
return result;
},

pick (source: any, ...keys: string[]) {
return keys.reduce((result: { [key: string]: any }, key) => {
if (source[key] !== undefined) {
result[key] = source[key];
}

return result;
}, {});
},

// Recursively merge the source object into the target object
merge (target: any, source: any) {
if (_.isObject(target) && _.isObject(source)) {
Object.keys(source).forEach(key => {
if (_.isObject(source[key])) {
if (!target[key]) {
Object.assign(target, { [key]: {} });
}

_.merge(target[key], source[key]);
} else {
Object.assign(target, { [key]: source[key] });
}
});
}
return target;
}
};

// Duck-checks if an object looks like a promise
export function isPromise (result: any) {
return _.isObject(result) &&
typeof result.then === 'function';
}

export function createSymbol (name: string) {
return typeof Symbol !== 'undefined' ? Symbol(name) : name;
}

export * from './debug.ts';
Loading

0 comments on commit dece8fb

Please sign in to comment.