1
0
mirror of https://github.com/pocketbase/pocketbase.git synced 2025-03-19 22:19:23 +02:00

removed JSVM Collection class aliases

This commit is contained in:
Gani Georgiev 2024-11-02 22:00:58 +02:00
parent a446290a7a
commit fadb4e3d67
4 changed files with 4586 additions and 4777 deletions

View File

@ -421,9 +421,6 @@ func baseBinds(vm *goja.Runtime) {
instance := &core.Collection{} instance := &core.Collection{}
return structConstructorUnmarshal(vm, call, instance) return structConstructorUnmarshal(vm, call, instance)
}) })
registerFactoryAsConstructor(vm, "BaseCollection", core.NewBaseCollection)
registerFactoryAsConstructor(vm, "AuthCollection", core.NewAuthCollection)
registerFactoryAsConstructor(vm, "ViewCollection", core.NewViewCollection)
vm.Set("FieldsList", func(call goja.ConstructorCall) *goja.Object { vm.Set("FieldsList", func(call goja.ConstructorCall) *goja.Object {
instance := &core.FieldsList{} instance := &core.FieldsList{}

View File

@ -43,7 +43,7 @@ func TestBaseBindsCount(t *testing.T) {
vm := goja.New() vm := goja.New()
baseBinds(vm) baseBinds(vm)
testBindsCount(vm, "this", 35, t) testBindsCount(vm, "this", 32, t)
} }
func TestBaseBindsSleep(t *testing.T) { func TestBaseBindsSleep(t *testing.T) {
@ -293,42 +293,6 @@ func TestBaseBindsCollection(t *testing.T) {
} }
} }
func TestBaseBindsCollectionFactories(t *testing.T) {
vm := goja.New()
baseBinds(vm)
scenarios := []struct {
js string
expectedType string
}{
{"new BaseCollection('test')", core.CollectionTypeBase},
{"new ViewCollection('test')", core.CollectionTypeView},
{"new AuthCollection('test')", core.CollectionTypeAuth},
}
for _, s := range scenarios {
t.Run(s.js, func(t *testing.T) {
v, err := vm.RunString(s.js)
if err != nil {
t.Fatal(err)
}
c, ok := v.Export().(*core.Collection)
if !ok {
t.Fatalf("Expected *core.Collection instance, got %T (%v)", c, c)
}
if c.Name != "test" {
t.Fatalf("Expected collection name %q, got %v", "test", c.Name)
}
if c.Type != s.expectedType {
t.Fatalf("Expected collection type %q, got %v", s.expectedType, c.Type)
}
})
}
}
func TestBaseBindsFieldsList(t *testing.T) { func TestBaseBindsFieldsList(t *testing.T) {
vm := goja.New() vm := goja.New()
baseBinds(vm) baseBinds(vm)

File diff suppressed because it is too large Load Diff

View File

@ -297,14 +297,16 @@ declare const Record: {
// note: declare as "newable" const due to conflict with the Record TS utility type // note: declare as "newable" const due to conflict with the Record TS utility type
} }
interface Collection extends core.Collection{} // merge interface Collection extends core.Collection{
type: "base" | "view" | "auth"
} // merge
/** /**
* Collection model class. * Collection model class.
* *
* ` + "```" + `js * ` + "```" + `js
* const collection = new Collection({ * const collection = new Collection({
* name: "article",
* type: "base", * type: "base",
* name: "article",
* listRule: "@request.auth.id != '' || status = 'public'", * listRule: "@request.auth.id != '' || status = 'public'",
* viewRule: "@request.auth.id != '' || status = 'public'", * viewRule: "@request.auth.id != '' || status = 'public'",
* deleteRule: "@request.auth.id != ''", * deleteRule: "@request.auth.id != ''",
@ -327,91 +329,7 @@ interface Collection extends core.Collection{} // merge
* @group PocketBase * @group PocketBase
*/ */
declare class Collection implements core.Collection { declare class Collection implements core.Collection {
constructor(data?: Partial<core.Collection>) constructor(data?: Partial<Collection>)
}
interface BaseCollection extends core.Collection{} // merge
/**
* Alias for a "base" collection class.
*
* ` + "```" + `js
* const collection = new BaseCollection({
* name: "article",
* listRule: "@request.auth.id != '' || status = 'public'",
* viewRule: "@request.auth.id != '' || status = 'public'",
* deleteRule: "@request.auth.id != ''",
* fields: [
* {
* name: "title",
* type: "text",
* required: true,
* min: 6,
* max: 100,
* },
* {
* name: "description",
* type: "text",
* },
* ]
* })
* ` + "```" + `
*
* @group PocketBase
*/
declare class BaseCollection implements core.Collection {
constructor(data?: Partial<core.Collection>)
}
interface AuthCollection extends core.Collection{} // merge
/**
* Alias for an "auth" collection class.
*
* ` + "```" + `js
* const collection = new AuthCollection({
* name: "clients",
* listRule: "@request.auth.id != '' || status = 'public'",
* viewRule: "@request.auth.id != '' || status = 'public'",
* deleteRule: "@request.auth.id != ''",
* fields: [
* {
* name: "title",
* type: "text",
* required: true,
* min: 6,
* max: 100,
* },
* {
* name: "description",
* type: "text",
* },
* ]
* })
* ` + "```" + `
*
* @group PocketBase
*/
declare class AuthCollection implements core.Collection {
constructor(data?: Partial<core.Collection>)
}
interface ViewCollection extends core.Collection{} // merge
/**
* Alias for a "view" collection class.
*
* ` + "```" + `js
* const collection = new ViewCollection({
* name: "clients",
* listRule: "@request.auth.id != '' || status = 'public'",
* viewRule: "@request.auth.id != '' || status = 'public'",
* deleteRule: "@request.auth.id != ''",
* viewQuery: "SELECT id, title from posts",
* })
* ` + "```" + `
*
* @group PocketBase
*/
declare class ViewCollection implements core.Collection {
constructor(data?: Partial<core.Collection>)
} }
interface FieldsList extends core.FieldsList{} // merge interface FieldsList extends core.FieldsList{} // merge