{"id":18304571,"url":"https://github.com/numtel/serverobject","last_synced_at":"2025-04-09T10:36:46.760Z","repository":{"id":21057885,"uuid":"24357073","full_name":"numtel/serverobject","owner":"numtel","description":"ServerObject Meteor Package","archived":false,"fork":false,"pushed_at":"2014-10-07T22:33:03.000Z","size":300,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-15T04:42:29.792Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/numtel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-09-23T04:44:44.000Z","updated_at":"2014-10-07T23:51:13.000Z","dependencies_parsed_at":"2022-09-15T00:30:58.592Z","dependency_job_id":null,"html_url":"https://github.com/numtel/serverobject","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/numtel%2Fserverobject","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/numtel%2Fserverobject/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/numtel%2Fserverobject/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/numtel%2Fserverobject/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/numtel","download_url":"https://codeload.github.com/numtel/serverobject/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248021406,"owners_count":21034661,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T15:29:24.610Z","updated_at":"2025-04-09T10:36:46.734Z","avatar_url":"https://github.com/numtel.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ServerObject Meteor Package\n\nCreate proxy objects on the client for even easier server integration.\n\n[![Build Status](https://travis-ci.org/numtel/serverobject.svg?branch=master)](https://travis-ci.org/numtel/serverobject)\n\n## Installation\n\nRun the following command\n\n    meteor add numtel:serverobject\n\n## Implements\n\n#### ServerObject()\n\n    var instance = ServerObject(\n                     type, // Key as defined in ServerObject.allow() on server\n                     [argument, argument...,] // Constructor arguments\n                     function(error, result){...} // Received callback\n                   );\n\nCreates a new instance of an object on the server. \nCan be called from both client and server.\n\nObject can be defined to local scope synchronously but all properties will be \nunavailable until the callback.\n\nThe first argument is a string corresponding with the object defined using ServerObject.allow().\nThe last argument is a callback function with parameters `error` and `instance` respectively.\nExtra arguments between the first and last will be passed along to the class constructor.\n\nThe instance's properties and methods will be accessible on the client. \nAll methods are now asynchronous, append a callback(`error, result`) argument to each method call.\n\nFor methods with their own callbacks, pass callback functions normally but do not forget about the last parameter always being a callback for the method's return value. See `serverobject-tests.js` for an example with multiple callbacks.\n\nInstance properties are copied from the server on construction, method calls, and any callbacks.\nWith the `forwardFromClient` option set, instance properties from the client are copied to the server on method calls.\n\nExcept for the `_id` property, prototype functions and object properties prefixed with an underscore will be considered private and unavailable through the instance proxy object.\n\n#### instance._close()\n\nClose and clean up an instance on the server.\n\n#### ServerObject.allow()\n\n    ServerObject.allow({\n      key: {\n        ref: reference, \n        [allowConstructor: function(args),]\n        [filterInstances: function(),]\n        [forwardFromClient: boolean]\n       }\n    })\n\nOnly available on the server, this method defines an object type for instantiation.\n\n`key` refers to a string that will identify this type of object. These keys are what is passed into `ServerObject()` as the `type` argument.\n\n`ref` refers to the variable containing the constructor function. (as in `new reference()`)\n\n`allowConstructor` accepts an optional function with one argument: an array of the arguments sent to the constructor. Return a boolean to determine whether to create the instance.\n\n`filterInstances` accepts and optional function with no arguments. The instance is passed as the context (access with `this`). To filter out the instance, `return undefined` to block transmission of the instance to the client. On success, `return this`. You may modify the values of the instance in this function.\n\n`forwardFromClient` accepts a boolean to determine whether to update values set on the client instance to the server on method calls. Defaults to false for heightened security.\n\n## Usage\n\nThe following is based on `serverobject-tests.js`.\n\nOn the server, create an object definition and register it with ServerObject.allow():\n\n    MyClass = function(id){\n      this.id = id || Random.id();\n    };\n    MyClass.prototype.reverseString = function(something){\n      if(typeof something !== 'string'){\n        throw new Meteor.Error(400,'Argument must be string!');\n      };\n      this.lastReversed = something;\n      return something.split('').reverse().join('');\n    };\n\n    MyClass.prototype.asyncWork = function(value, callback){\n      setTimeout(function(){\n        callback(value);\n      }, 1000);\n    };\n\n    // Register the mockup class with ServerObject\n    ServerObject.allow({\n      'MyClass': {\n        ref: MyClass,\n        allowConstructor: function(args){\n          return typeof args[0] === 'string';\n        },\n        filterInstances: function(){\n          if(this.id !== 'test1'){\n            return undefined;\n          };\n          return this;\n        }\n      }\n    });\n\n\nOn the client (or server), create an instance using ServerObject:\n\n    ServerObject('MyClass', 'test1', function(error, instance){\n      instance.reverseString('hello', function(error, result){\n        console.log(result); // Print 'olleh'\n        console.log(instance.lastReversed); // Print 'hello'\n      });\n\n      // Last argument undefined to discard the normal function return callback\n      instance.asyncWork('hello', function(value){\n        console.log(value); // Print 'hello'\n      }, undefined);\n    });\n\n## Notes\n\n* All thrown errors should use `Meteor.Error()`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnumtel%2Fserverobject","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnumtel%2Fserverobject","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnumtel%2Fserverobject/lists"}