@fauna-labs/fql-utilities
Advanced tools
Comparing version 0.1.1 to 0.1.2
import faunadb from 'faunadb'; | ||
/** | ||
* @param {Array<any>} array - The array to take the tail from. | ||
* @returns {Array<any>} - The tail of the array. | ||
* | ||
* Tail() accepts a Fauna Array and returns a new array consisting of every | ||
* element except the first. If the array is empty, Tail() returns an empty array. | ||
* | ||
* ### Consumes per call | ||
* * 0 Read Ops | ||
* * 0 Write Ops | ||
* * 1 ComputeOp (19 FQL verbs) | ||
* | ||
* ### Dependencies: | ||
* none | ||
* | ||
* ### Usage in Fauna Schema Migrate: | ||
* ```js | ||
* import { Tail } from '@fauna-labs/fql-utilities/collections'; | ||
* export default Tail(); | ||
* ``` | ||
* | ||
* ### Usage in FQL: | ||
* ```fql | ||
* Let( | ||
* { | ||
* array: [0, 1, 2], | ||
* shortArray: Call("Tail", Var("array")) | ||
* }, | ||
* Equals(Count(Var("shortArray")), 2) // true | ||
* ) | ||
*``` | ||
*/ | ||
export declare function Tail(): faunadb.Expr; | ||
export declare function Tail(replace?: boolean): faunadb.Expr; |
@@ -27,3 +27,3 @@ "use strict"; | ||
const q = faunadb_1.default.query; | ||
const { Abort, Count, If, IsArray, Lambda, Let, LT, Query, Reverse, Subtract, Take, Var } = q; | ||
const { Abort, Count, Exists, If, IsArray, Lambda, Let, LT, Query, Update, Reverse, Subtract, Take, Var } = q; | ||
/** | ||
@@ -61,6 +61,14 @@ * @param {Array<any>} array - The array to take the tail from. | ||
*/ | ||
function Tail() { | ||
const body = Query(Lambda(["array"], If(IsArray(Var("array")), Let({ tail_length: Subtract(Count(Var("array")), 1) }, If(LT(Var("tail_length"), 0), Var("array"), Reverse(Take(Var("tail_length"), Reverse(Var("array")))))), Abort("Tail() requires one argument that is an array.")))); | ||
// export function Tail(): faunadb.Expr { | ||
// return If( | ||
// Exists(Function("Tail")), | ||
// Update(Function("Tail"), { body: body }), | ||
// CreateFunction({ name: "Tail", body: body }) | ||
// ); | ||
// } | ||
function Tail(replace = false) { | ||
return (0, faunadb_1.CreateFunction)({ | ||
name: "Tail", | ||
body: Query(Lambda(["array"], If(IsArray(Var("array")), Let({ tail_length: Subtract(Count(Var("array")), 1) }, If(LT(Var("tail_length"), 0), Var("array"), Reverse(Take(Var("tail_length"), Reverse(Var("array")))))), Abort("Tail() requires one argument that is an array.")))) | ||
body: body | ||
}); | ||
@@ -67,0 +75,0 @@ } |
{ | ||
"name": "@fauna-labs/fql-utilities", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "A library of FQL utilities for Fauna Schema Migrate, implemented in TypeScript.", | ||
@@ -10,3 +10,3 @@ "main": "dist/index.js", | ||
"prepare": "tsc", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "jest" | ||
}, | ||
@@ -37,4 +37,10 @@ "repository": { | ||
"devDependencies": { | ||
"@babel/core": "^7.15.8", | ||
"@babel/preset-env": "^7.15.8", | ||
"@babel/preset-typescript": "^7.15.0", | ||
"@types/jest": "^27.0.2", | ||
"babel-jest": "^27.2.5", | ||
"jest": "^27.2.5", | ||
"typescript": "^4.4.3" | ||
} | ||
} |
@@ -16,3 +16,3 @@ { | ||
"exclude": ["node_modules", "test", "dist"], | ||
"include": ["src/**/*"] | ||
"include": ["src/**/*", "tests/index.test.ts"] | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
45511
37
696
1
0
7