Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion javascript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "retoolrpc",
"version": "0.1.7",
"version": "0.1.8",
"description": "TypeScript package for Retool RPC",
"keywords": [],
"homepage": "https://github.com/tryretool/retoolrpc#readme",
Expand Down
11 changes: 11 additions & 0 deletions javascript/src/addons/sequelize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ type RegisterModelArgs = {
readAttributes?: string[]
writeAttributes?: string[]
findByAttributes?: string[]
permissions?: {
groupNames?: string[]
userEmails?: string[]
}
}

export declare class MyMixinInterface {
Expand Down Expand Up @@ -35,6 +39,7 @@ function registerModel({
readAttributes,
writeAttributes,
findByAttributes,
permissions,
}: RegisterModelArgs & { rpc: RetoolRPC }) {
const modelName = capitalize(model.name)
// this will give us not just the name of the attribute, but also their type
Expand All @@ -57,6 +62,7 @@ function registerModel({
rpc.register({
name: `${modelName} > create`,
arguments: writeAttributeArgs,
permissions,
implementation: async (args) => {
if (typeof args !== 'object' || Array.isArray(args)) {
throw 'attributes must be an object'
Expand All @@ -76,6 +82,7 @@ function registerModel({
primaryKey: { type: 'string', required: true },
...writeAttributeArgs,
},
permissions,
implementation: async ({ primaryKey, ...attributes }) => {
return model.update(attributes, {
where: {
Expand All @@ -91,6 +98,7 @@ function registerModel({
findAttributes: { type: 'dict', required: true },
...writeAttributeArgs,
},
permissions,
implementation: async ({ findAttributes, ...writeAttributes }) => {
// Note: this is susceptible to race condition if there is no unique index
// on the find attributes. It's the user's responsibility to avoid
Expand All @@ -115,6 +123,7 @@ function registerModel({
offset: { type: 'number' },
limit: { type: 'number' },
},
permissions,
implementation: async ({ offset, limit }) => {
return model.findAll({
attributes: readAttributes,
Expand All @@ -130,6 +139,7 @@ function registerModel({
arguments: {
primaryKey: { type: 'string', required: true },
},
permissions,
implementation: async ({ primaryKey }) => {
return model.findByPk(primaryKey, {
attributes: readAttributes,
Expand All @@ -141,6 +151,7 @@ function registerModel({
rpc.register({
name: `${modelName} > findBy`,
arguments: findByAttributeArgs,
permissions,
implementation: async (attributesValues) => {
return model.findAll({
where: attributesValues,
Expand Down
2 changes: 1 addition & 1 deletion javascript/src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const RetoolRPCVersion = '0.1.7'
export const RetoolRPCVersion = '0.1.8'