New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@embracesql/client

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@embracesql/client - npm Package Compare versions

Comparing version 0.0.8 to 0.0.9

6

package.json
{
"name": "@embracesql/client",
"version": "0.0.8",
"version": "0.0.9",
"description": "Connects to EmbraceSQL over HTTP/S from browser and node.",

@@ -13,5 +13,5 @@ "type": "module",

"dependencies": {
"@embracesql/shared": "^0.0.8"
"@embracesql/shared": "^0.0.9"
},
"gitHead": "92c10ccba1bac0a6e94cd89576f0c73d16cf5bcf"
"gitHead": "149e4adeacf43a8b41c906a492e5ddeb4ed0114b"
}
import {
ASTKind,
BY_PRIMARY_KEY,
FunctionOperationNode,

@@ -7,4 +8,22 @@ GenerationContext,

NamedASTNode,
TableNode,
} from "@embracesql/shared";
function returnParsedRows(table: TableNode): string {
return `(
response.results
?.map(${table.type.typescriptNamespacedName}.parse)
.map(nullIsUndefined<${table.typescriptNamespacedName}.Record>)
.filter((x): x is ${table.typescriptNamespacedName}.Record => x !== undefined) ?? []
)
`;
}
function returnParsedRow(table: TableNode): string {
return `(
nullIsUndefined<${table.typescriptNamespacedName}.Record>(${table.type.typescriptNamespacedName}.parse(response.results))
)
`;
}
export const NestedNamedClassVisitor = {

@@ -31,2 +50,8 @@ before: async (context: GenerationContext, node: NamedASTNode) => {

: `${node.index.table.typescriptNamespacedName}.Record[] | undefined`;
const parametersPick = node.index.columns
.map(
(c) =>
`${c.typescriptPropertyName}: parameters.${c.typescriptPropertyName}`,
)
.join(",");
const generationBuffer = [

@@ -37,3 +62,3 @@ `

operation: "${node.typescriptNamespacedPropertyName}",
parameters
parameters: {${parametersPick}}
});

@@ -44,4 +69,4 @@ `,

node.index.unique
? `return response.results ? response.results : undefined`
: `return response.results ? response.results : []`,
? `return ${returnParsedRow(node.index.table)};`
: `return ${returnParsedRows(node.index.table)};`,
);

@@ -121,3 +146,13 @@ return generationBuffer.join("\n");

[ASTKind.Table]: NestedNamedClassVisitor,
[ASTKind.Index]: NestedNamedClassVisitor,
[ASTKind.Index]: {
before: NestedNamedClassVisitor.before,
after: async (context, node) => {
return [
await NestedNamedClassVisitor.after(context, node),
node.primaryKey
? `public get ${BY_PRIMARY_KEY}(){ return this.${node.typescriptName} };`
: ``,
].join("\n");
},
},
[ASTKind.Scripts]: NestedNamedClassVisitor,

@@ -136,2 +171,8 @@ [ASTKind.ScriptFolder]: NestedNamedClassVisitor,

const returnType = `${node.table.typescriptNamespacedName}.Record`;
const valuesPick = node.table.allColumns
.map(
(c) =>
`${c.typescriptPropertyName}: values.${c.typescriptPropertyName}`,
)
.join(",");
return `

@@ -141,5 +182,5 @@ public async create(values: ${valuesType}) : Promise<${returnType}|undefined> {

operation: "${node.typescriptNamespacedPropertyName}",
values
values: {${valuesPick}}
});
return response.results;
return ${returnParsedRow(node.table)};
}

@@ -149,2 +190,19 @@ `;

},
[ASTKind.AllOperation]: {
before: async (_, node) => {
// all those rows
return `
public async all() : Promise<${
node.table.typescriptNamespacedName
}.Record[]> {
const response = await this.client.invoke<never, never, ${
node.table.typescriptNamespacedName
}.Record[]>({
operation: "${node.typescriptNamespacedPropertyName}"
});
return ${returnParsedRows(node.table)};
}
`;
},
},

@@ -162,2 +220,14 @@ // with the `returns` deletes and reads have the same structure

: `${node.index.table.typescriptNamespacedName}.Record[] | undefined`;
const parametersPick = node.index.columns
.map(
(c) =>
`${c.typescriptPropertyName}: parameters.${c.typescriptPropertyName}`,
)
.join(",");
const valuesPick = node.index.table.allColumns
.map(
(c) =>
`${c.typescriptPropertyName}: values.${c.typescriptPropertyName}`,
)
.join(",");
const generationBuffer = [

@@ -168,4 +238,4 @@ `

operation: "${node.typescriptNamespacedPropertyName}",
parameters,
values
parameters: {${parametersPick}},
values: {${valuesPick}}
});

@@ -176,4 +246,4 @@ `,

node.index.unique
? `return response.results ? response.results : undefined`
: `return response.results ? response.results : []`,
? `return ${returnParsedRow(node.index.table)};`
: `return ${returnParsedRows(node.index.table)};`,
);

@@ -180,0 +250,0 @@ return generationBuffer.join("\n");

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc