Skip to content

Commit

Permalink
roar
Browse files Browse the repository at this point in the history
  • Loading branch information
stopachka committed Nov 26, 2024
1 parent 6f43826 commit 98f60b8
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 16 deletions.
2 changes: 2 additions & 0 deletions client/packages/admin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
type InstantUnknownSchema,
type InstaQLEntity,
type InstaQLResult,
type InstantRules,
} from "@instantdb/core";

import version from "./version";
Expand Down Expand Up @@ -931,4 +932,5 @@ export {
type InstantUnknownSchema,
type InstaQLEntity,
type InstaQLResult,
type InstantRules,
};
10 changes: 6 additions & 4 deletions client/packages/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ async function pullSchema(appId, { pkgDir, instantModuleName }) {
return true;
}

async function pullPerms(appId, { pkgDir }) {
async function pullPerms(appId, { pkgDir, instantModuleName }) {
console.log("Pulling perms...");

const pullRes = await fetchJson({
Expand All @@ -742,7 +742,7 @@ async function pullPerms(appId, { pkgDir }) {
const permsPath = join(pkgDir, "instant.perms.ts");
await writeTypescript(
permsPath,
generatePermsTypescriptFile(pullRes.data.perms || {}),
generatePermsTypescriptFile(pullRes.data.perms || {}, instantModuleName),
"utf-8",
);

Expand Down Expand Up @@ -1478,7 +1478,7 @@ function appDashUrl(id) {
return `${instantDashOrigin}/dash?s=main&t=home&app=${id}`;
}

function generatePermsTypescriptFile(perms) {
function generatePermsTypescriptFile(perms, instantModuleName) {
const rulesTxt = Object.keys(perms).length
? JSON.stringify(perms, null, 2)
: `
Expand All @@ -1504,7 +1504,9 @@ function generatePermsTypescriptFile(perms) {
return `
// Docs: https://www.instantdb.com/docs/permissions
const rules = ${rulesTxt};
import { type InstantRules } from "${instantModuleName ?? "@instantdb/core"}";
const rules = ${rulesTxt} satisfies InstantRules;
export default rules;
`.trim();
Expand Down
2 changes: 2 additions & 0 deletions client/packages/react-native/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
type InstantConfig,
type InstantSchemaDef,
type InstantUnknownSchema,
type InstantRules,
} from "@instantdb/core";

/**
Expand Down Expand Up @@ -146,4 +147,5 @@ export {
type InstantSchemaDef,
type InstantUnknownSchema,
type BackwardsCompatibleSchema,
type InstantRules,
};
2 changes: 2 additions & 0 deletions client/packages/react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
type InstantUnknownSchema,
type InstantSchemaDef,
type BackwardsCompatibleSchema,
type InstantRules,
} from "@instantdb/core";

import { InstantReact } from "./InstantReact";
Expand Down Expand Up @@ -94,4 +95,5 @@ export {
type InstantUnknownSchema,
type InstantSchemaDef,
type BackwardsCompatibleSchema,
type InstantRules,
};
36 changes: 24 additions & 12 deletions client/sandbox/strong-init-vite/instant.perms.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
type InstantRules = {
[EntityName: string]: {
allow: {
view?: string;
create?: string;
update?: string;
delete?: string;
};
bind?: string[];
};
};
// Docs: https://www.instantdb.com/docs/permissions

import { type InstantRules } from "@instantdb/react";

const rules = {
attrs: {
allow: {
create: "false",
},
bind: ["admin", "foo", "bar", "biz"],
},
posts: {
bind: [
"isAdmin",
"auth.email == '[email protected]'",
"isOwner",
"auth.uid == data.author",
],
allow: {
create: "isAdmin || isOwner",
delete: "isAdmin || isOwner",
update: "isAdmin || isOwner",
},
},
postBodies: {
bind: ["isAdmin", "auth.email == '[email protected]'"],
allow: {
create: "isAdmin",
delete: "isAdmin",
update: "isAdmin",
},
},
} satisfies InstantRules;

Expand Down

0 comments on commit 98f60b8

Please sign in to comment.