Skip to content

Commit

Permalink
refactor!: export default as 'feathersCasl' (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
fratzinger authored Mar 29, 2023
1 parent 0a5cf78 commit 722b5f5
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 18 deletions.
6 changes: 3 additions & 3 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ pnpm i feathers-casl @casl/ability

```ts
// app.ts
import casl from "feathers-casl";
import { feathersCasl } from "feathers-casl";

app.configure(casl());
app.configure(feathersCasl());
```

The `casl()` function can be configured, to provide app wide options to `feathers-casl`
The `feathersCasl()` function can be configured, to provide app wide options to `feathers-casl`

### Define static rules

Expand Down
8 changes: 1 addition & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ export * from "./hooks";
export * from "./channels";
export * from "./utils";

import initialize from "./initialize";

export default initialize;
export { initialize as feathersCasl } from "./initialize";

export * from "./types";

if (typeof module !== "undefined") {
module.exports = Object.assign(initialize, module.exports);
}
2 changes: 1 addition & 1 deletion src/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
InitOptions,
} from "./types";

export default (
export const initialize = (
options?: PartialDeep<InitOptions>
): ((app: Application) => void) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
Expand Down
6 changes: 3 additions & 3 deletions test/app/options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import assert from "node:assert";
import type { Application, HookContext } from "@feathersjs/feathers";
import { feathers } from "@feathersjs/feathers";
import { MemoryService } from "@feathersjs/memory";
import casl, { authorize } from "../../src";
import { feathersCasl, authorize } from "../../src";
import type { RealTimeConnection } from "@feathersjs/transport-commons";
import type { InitOptions } from "../../src";
import { defineAbility } from "@casl/ability";
Expand Down Expand Up @@ -59,7 +59,7 @@ describe("app-options / service-options", function () {
let calledChannelAbility = false;
let calledChannelModelName = false;
app.configure(
casl({
feathersCasl({
authorizeHook: {
actionOnForbidden: () => {
calledActionOnForbidden = true;
Expand Down Expand Up @@ -155,7 +155,7 @@ describe("app-options / service-options", function () {
});

app.configure(
casl({
feathersCasl({
authorizeHook: {
actionOnForbidden: () => {
appCalled.calledActionOnForbidden = true;
Expand Down
4 changes: 2 additions & 2 deletions test/channels/.mockServer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { MemoryService } from "@feathersjs/memory";
process.env["NODE_CONFIG_DIR"] = path.join(__dirname, "config/");
import configuration from "@feathersjs/configuration";

import casl from "../../../src";
import { feathersCasl } from "../../../src";

interface MockServerOptions {
channels: (app: Application) => void;
Expand Down Expand Up @@ -56,7 +56,7 @@ export const mockServer = (options: MockServerOptions) => {
const comments = app.service("comments");
const users = app.service("users");

app.configure(casl());
app.configure(feathersCasl());
return {
app: app,
articles,
Expand Down
11 changes: 9 additions & 2 deletions test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import assert from "node:assert";
import index, {
import {
feathersCasl,
authorize,
checkBasicPermission,
getChannelsWithReadAbility,
checkBasicPermissionUtil,
checkCan,
makeChannelOptions,
} from "../src";
import { feathers } from "@feathersjs/feathers";

Expand All @@ -18,13 +22,16 @@ describe("index", function () {
it("default is initialize", function () {
const app = feathers();
assert.ok(!app.get("casl"), "casl is not set");
index()(app);
feathersCasl()(app);
assert.ok(app.get("casl"), "casl is set");
});

it("destructured exports", function () {
assert.ok(authorize, "authorize is ok");
assert.ok(checkBasicPermission, "checkBasicPermission is ok");
assert.ok(getChannelsWithReadAbility, "getChannelsWithReadAbility is ok");
assert.ok(checkCan);
assert.ok(checkBasicPermissionUtil);
assert.ok(makeChannelOptions);
});
});

0 comments on commit 722b5f5

Please sign in to comment.